#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>

#include "Garfield/FundamentalConstants.hh"
#include "Garfield/OpticalData.hh"

namespace {

double Evaluate(const double y, const double a, const double b, const double c,
                const double d) {
  const double y2 = y * y;
  const double y3 = y2 * y;
  return a * y2 + b * y3 + c * y2 * y2 + d * y2 * y3;
}

template <std::size_t SIZE>
float Interpolate(const std::array<float, SIZE>& xs,
                  const std::array<float, SIZE>& ys, const float x) {
  const auto begin = std::begin(xs);
  const auto end = std::end(xs);
  const auto it1 = std::upper_bound(begin, end, x);
  if (it1 == begin) return ys.front();
  if (it1 == end) return ys.back();
  const auto it0 = std::prev(it1);
  const auto y0 = ys[it0 - begin];
  const auto y1 = ys[it1 - begin];
  // Linear interpolation.
  return y0 + (x - *it0) * (y1 - y0) / (*it1 - *it0);
}
}

namespace Garfield {

OpticalData::OpticalData() {}

bool OpticalData::IsAvailable(const std::string& material) const {
  std::array<std::string, 9> materials = {
      {"Ne", "Ar", "CO2", "CH4", "C2H6", "nC4H10", "C2H2", "CF4", "N2"}};
  auto result = std::find(materials.begin(), materials.end(), material);
  return result != materials.end();
}

bool OpticalData::GetPhotoabsorptionCrossSection(const std::string& material,
                                                 const double e, double& cs,
                                                 double& eta) {
  cs = eta = 0.;
  if (material == "Ne") return PhotoAbsorptionCsNeon(e, cs, eta);
  if (material == "Ar") return PhotoAbsorptionCsArgon(e, cs, eta);
  if (material == "CO2") return PhotoAbsorptionCsCO2(e, cs, eta);
  if (material == "CH4") return PhotoAbsorptionCsMethane(e, cs, eta);
  if (material == "C2H6") return PhotoAbsorptionCsEthane(e, cs, eta);
  if (material == "nC4H10") return PhotoAbsorptionCsButane(e, cs, eta);
  if (material == "C2H2") return PhotoAbsorptionCsAcetylene(e, cs, eta);
  if (material == "CF4") return PhotoAbsorptionCsCF4(e, cs, eta);
  if (material == "N2") return PhotoAbsorptionCsNitrogen(e, cs, eta);
  return false;
}

bool OpticalData::PhotoAbsorptionCsNeon(const double e, double& cs,
                                        double& eta) {
  // Sources:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109

  constexpr double ip12 = 21.6613;

  if (e < ip12) {
    cs = eta = 0.;
    return true;
  }

  double a, b, c, d;
  if (e < 48.475) {
    a = 16.13668;
    b = -38.9941;
    c = 35.96058;
    d = -12.319;
  } else if (e < 250.0) {
    a = 5.806197;
    b = 73.98605;
    c = -328.517;
    d = 353.6014;
  } else if (e < 280.0) {
    a = -2071.35;
    b = 76715.55;
    c = -942469.;
    d = 3857740.;
  } else if (e < 870.25) {
    a = 0.766927;
    b = 170.951;
    c = -971.918;
    d = 2191.973;
  } else if (e < 2984.3) {
    a = 3.401404;
    b = 4655.156;
    c = -92346.7;
    d = 683347.;
  } else {
    a = -2.13904;
    b = 5956.894;
    c = -185028.;
    d = 2306776.;
  }

  const double f = Evaluate(ip12 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsArgon(const double e, double& cs,
                                         double& eta) {
  // Sources:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109

  constexpr double ip32 = 15.7596103;
  constexpr double ip12 = 15.9371039;

  if (e < ip32) {
    cs = eta = 0.;
    return true;
  } else if (e < ip12) {
    // Continuum contribution between IP 3/2 and IP 1/2
    cs = 20.75e-18;
    eta = 1.;
    return true;
  }

  if (e >= 243. && e <= 336.) {
    // L23 edge
    constexpr size_t nEntries = 130;
    constexpr std::array<float, nEntries> xAr = {
        {2.4300e02, 2.4400e02, 2.4450e02, 2.4500e02, 2.4550e02, 2.4600e02,
         2.4650e02, 2.4700e02, 2.4750e02, 2.4800e02, 2.4850e02, 2.4900e02,
         2.4950e02, 2.5000e02, 2.5050e02, 2.5100e02, 2.5150e02, 2.5200e02,
         2.5250e02, 2.5300e02, 2.5350e02, 2.5400e02, 2.5450e02, 2.5500e02,
         2.5550e02, 2.5600e02, 2.5650e02, 2.5700e02, 2.5750e02, 2.5800e02,
         2.5850e02, 2.5900e02, 2.5950e02, 2.6000e02, 2.6050e02, 2.6100e02,
         2.6150e02, 2.6200e02, 2.6250e02, 2.6300e02, 2.6350e02, 2.6400e02,
         2.6450e02, 2.6500e02, 2.6550e02, 2.6600e02, 2.6650e02, 2.6700e02,
         2.6750e02, 2.6800e02, 2.6850e02, 2.6900e02, 2.6950e02, 2.7000e02,
         2.7050e02, 2.7100e02, 2.7150e02, 2.7200e02, 2.7250e02, 2.7300e02,
         2.7350e02, 2.7400e02, 2.7450e02, 2.7500e02, 2.7550e02, 2.7600e02,
         2.7650e02, 2.7700e02, 2.7750e02, 2.7800e02, 2.7850e02, 2.7900e02,
         2.7950e02, 2.8000e02, 2.8100e02, 2.8200e02, 2.8300e02, 2.8400e02,
         2.8500e02, 2.8600e02, 2.8700e02, 2.8800e02, 2.8900e02, 2.9000e02,
         2.9100e02, 2.9200e02, 2.9300e02, 2.9400e02, 2.9500e02, 2.9600e02,
         2.9700e02, 2.9800e02, 2.9900e02, 3.0000e02, 3.0100e02, 3.0200e02,
         3.0300e02, 3.0400e02, 3.0500e02, 3.0600e02, 3.0700e02, 3.0800e02,
         3.0900e02, 3.1000e02, 3.1100e02, 3.1200e02, 3.1300e02, 3.1400e02,
         3.1500e02, 3.1600e02, 3.1700e02, 3.1800e02, 3.1900e02, 3.2000e02,
         3.2100e02, 3.2200e02, 3.2300e02, 3.2400e02, 3.2500e02, 3.2600e02,
         3.2700e02, 3.2800e02, 3.2900e02, 3.3000e02, 3.3100e02, 3.3200e02,
         3.3300e02, 3.3400e02, 3.3500e02, 3.3600e02}};
    constexpr std::array<float, nEntries> yAr = {
        {4.1053e-01, 5.7040e-01, 8.3784e-01, 7.6382e-01, 5.8520e-01, 6.0099e-01,
         1.0352,     1.5938,     1.8138,     1.9737,     2.2698,     2.6546,
         3.0888,     3.3750,     3.5428,     3.7204,     3.8092,     3.8882,
         3.8882,     3.9178,     4.3657,     4.3323,     4.3212,     4.2324,
         4.1990,     4.1768,     4.0991,     4.0546,     4.0324,     3.9769,
         3.9658,     3.9435,     3.8658,     3.8769,     3.8102,     3.7769,
         3.8213,     3.7658,     3.7547,     3.7325,     3.7214,     2.7106,
         2.6945,     2.7106,     2.6945,     2.6945,     2.7026,     2.7026,
         2.7106,     2.6945,     2.6864,     2.6380,     2.5977,     2.5735,
         2.5332,     3.3806,     3.3697,     3.3697,     3.3367,     3.3258,
         3.3148,     3.3148,     3.3038,     3.2819,     3.2489,     3.2599,
         3.2489,     3.2489,     3.1940,     3.2050,     3.1940,     3.1831,
         3.2050,     3.1721,     3.1611,     3.1501,     3.1282,     3.1501,
         3.1172,     3.1282,     3.1062,     3.1062,     3.1062,     3.0843,
         3.0623,     3.0623,     3.0404,     3.0294,     3.0075,     3.0294,
         3.0184,     3.0075,     2.9745,     2.9745,     2.9965,     2.9635,
         2.9306,     2.9306,     2.9306,     2.9196,     2.9306,     2.8977,
         2.8757,     2.8867,     2.8867,     2.8757,     2.8757,     2.8867,
         2.8428,     2.8209,     2.8428,     2.8428,     2.8209,     2.8428,
         2.8428,     2.8538,     2.9196,     2.9635,     3.0075,     3.0075,
         2.9635,     3.0075,     2.9526,     2.9526,     2.9087,     2.8648,
         2.8977,     2.8757,     2.8648,     2.8318}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xAr, yAr, e);
    eta = 1.;
    return true;
  }

  double a, b, c, d;
  if (e < 29.2395) {
    a = -25.4281;
    b = 170.7881;
    c = -247.886;
    d = 106.5586;
  } else if (e < 48.) {
    a = 76.97689;
    b = -573.622;
    c = 1358.922;
    d = -976.888;
  } else if (e < 79.3) {
    a = 14.43074;
    b = -40.8325;
    c = -115.985;
    d = 347.5945;
  } else if (e < 243.) {
    a = 5.617571;
    b = 128.2189;
    c = -1203.47;
    d = 2660.151;
  } else if (e < 500.) {
    a = -11.8768;
    b = 8371.694;
    c = -109963.;
    d = 0.;
  } else if (e < 929.7) {
    a = 35.65584;
    b = 4922.702;
    c = 8315.576;
    d = -1757750.;
  } else if (e < 3206.) {
    a = 20.59692;
    b = 6151.107;
    c = -2513.47;
    d = -2337467.;
  } else if (e < 6199.3) {
    a = -1004.53;
    b = 954912.7;
    c = -220652027.;
    d = 17883565552.;
  } else {
    a = 12.26308;
    b = 132886.9;
    c = -5911229.;
    d = -624237063.;
  }

  const double f = Evaluate(ip12 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsCO2(const double e, double& cs,
                                       double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109
  // Photoionization yield:
  // Nakata et al., Science of Light 14 (1965), 14
  // Barrus et al., Phys. Rev. A 20 (1979), 1045
  // Ukai et al., J. Chem. Phys. 97 (1992), 2835

  if (e < 7.) {
    cs = eta = 0.;
    return true;
  }

  const double ip = 13.7763;

  if (e < 107.) {
    // Photoabsorption cross-section
    constexpr size_t nPacsEntries = 1072;

    constexpr std::array<float, nPacsEntries> xCO2 = {
        {7.0000,   7.3120,   7.5360,   7.7130,   7.8620,   8.0170,   8.1810,
         8.3290,   8.5750,   8.7380,   8.8800,   9.0360,   9.2060,   9.3480,
         9.4850,   9.5720,   9.6760,   9.8120,   9.9500,   1.0080e1, 1.0170e1,
         1.0330e1, 1.0660e1, 1.0715e1, 1.0727e1, 1.0794e1, 1.0842e1, 1.0875e1,
         1.0923e1, 1.0978e1, 1.0990e1, 1.1045e1, 1.1071e1, 1.1112e1, 1.1133e1,
         1.1167e1, 1.1193e1, 1.1241e1, 1.1262e1, 1.1322e1, 1.1336e1, 1.1377e1,
         1.1403e1, 1.1418e1, 1.1470e1, 1.1492e1, 1.1525e1, 1.1544e1, 1.1585e1,
         1.1621e1, 1.1666e1, 1.1714e1, 1.1735e1, 1.1769e1, 1.1817e1, 1.1843e1,
         1.1876e1, 1.1917e1, 1.1924e1, 1.1965e1, 1.2017e1, 1.2053e1, 1.2087e1,
         1.2139e1, 1.2180e1, 1.2221e1, 1.2254e1, 1.2295e1, 1.2357e1, 1.2405e1,
         1.2438e1, 1.2471e1, 1.2526e1, 1.2565e1, 1.2601e1, 1.2634e1, 1.2675e1,
         1.2701e1, 1.2742e1, 1.2801e1, 1.2823e1, 1.2842e1, 1.2918e1, 1.2937e1,
         1.2971e1, 1.3033e1, 1.3093e1, 1.3160e1, 1.3167e1, 1.3196e1, 1.3229e1,
         1.3262e1, 1.3296e1, 1.3344e1, 1.3411e1, 1.3432e1, 1.3458e1, 1.3485e1,
         1.3518e1, 1.3559e1, 1.3592e1, 1.3621e1, 1.3647e1, 1.3681e1, 1.3729e1,
         1.3755e1, 1.3776e1, 1.3780e1, 1.3783e1, 1.3786e1, 1.3790e1, 1.3794e1,
         1.3796e1, 1.3799e1, 1.3803e1, 1.3806e1, 1.3814e1, 1.3818e1, 1.3821e1,
         1.3825e1, 1.3827e1, 1.3831e1, 1.3835e1, 1.3839e1, 1.3843e1, 1.3846e1,
         1.3849e1, 1.3853e1, 1.3857e1, 1.3863e1, 1.3868e1, 1.3872e1, 1.3874e1,
         1.3878e1, 1.3881e1, 1.3884e1, 1.3887e1, 1.3891e1, 1.3894e1, 1.3902e1,
         1.3908e1, 1.3914e1, 1.3916e1, 1.3921e1, 1.3925e1, 1.3933e1, 1.3937e1,
         1.3938e1, 1.3942e1, 1.3947e1, 1.3950e1, 1.3953e1, 1.3959e1, 1.3962e1,
         1.3965e1, 1.3972e1, 1.3982e1, 1.3984e1, 1.3988e1, 1.3995e1, 1.3999e1,
         1.4002e1, 1.4008e1, 1.4012e1, 1.4014e1, 1.4019e1, 1.4026e1, 1.4030e1,
         1.4035e1, 1.4038e1, 1.4041e1, 1.4047e1, 1.4050e1, 1.4059e1, 1.4065e1,
         1.4072e1, 1.4077e1, 1.4083e1, 1.4087e1, 1.4093e1, 1.4104e1, 1.4112e1,
         1.4130e1, 1.4137e1, 1.4142e1, 1.4153e1, 1.4189e1, 1.4194e1, 1.4200e1,
         1.4206e1, 1.4215e1, 1.4223e1, 1.4246e1, 1.4254e1, 1.4290e1, 1.4296e1,
         1.4308e1, 1.4318e1, 1.4349e1, 1.4356e1, 1.4403e1, 1.4456e1, 1.4465e1,
         1.4504e1, 1.4513e1, 1.4542e1, 1.4611e1, 1.4663e1, 1.4671e1, 1.4680e1,
         1.4710e1, 1.4752e1, 1.4805e1, 1.4836e1, 1.4847e1, 1.4862e1, 1.4878e1,
         1.4898e1, 1.4921e1, 1.4938e1, 1.4943e1, 1.4961e1, 1.4977e1, 1.4985e1,
         1.5007e1, 1.5023e1, 1.5043e1, 1.5062e1, 1.5081e1, 1.5086e1, 1.5097e1,
         1.5106e1, 1.5114e1, 1.5124e1, 1.5134e1, 1.5139e1, 1.5144e1, 1.5159e1,
         1.5178e1, 1.5187e1, 1.5194e1, 1.5208e1, 1.5225e1, 1.5239e1, 1.5252e1,
         1.5256e1, 1.5268e1, 1.5282e1, 1.5289e1, 1.5323e1, 1.5328e1, 1.5342e1,
         1.5348e1, 1.5363e1, 1.5366e1, 1.5371e1, 1.5384e1, 1.5394e1, 1.5401e1,
         1.5413e1, 1.5425e1, 1.5437e1, 1.5448e1, 1.5463e1, 1.5480e1, 1.5486e1,
         1.5495e1, 1.5511e1, 1.5529e1, 1.5542e1, 1.5545e1, 1.5550e1, 1.5563e1,
         1.5567e1, 1.5581e1, 1.5584e1, 1.5590e1, 1.5604e1, 1.5612e1, 1.5615e1,
         1.5633e1, 1.5640e1, 1.5655e1, 1.5668e1, 1.5680e1, 1.5685e1, 1.5707e1,
         1.5712e1, 1.5716e1, 1.5723e1, 1.5725e1, 1.5731e1, 1.5735e1, 1.5738e1,
         1.5744e1, 1.5749e1, 1.5753e1, 1.5763e1, 1.5774e1, 1.5784e1, 1.5790e1,
         1.5795e1, 1.5806e1, 1.5812e1, 1.5820e1, 1.5843e1, 1.5853e1, 1.5863e1,
         1.5871e1, 1.5878e1, 1.5886e1, 1.5894e1, 1.5897e1, 1.5905e1, 1.5908e1,
         1.5914e1, 1.5921e1, 1.5924e1, 1.5932e1, 1.5937e1, 1.5944e1, 1.5946e1,
         1.5951e1, 1.5956e1, 1.5962e1, 1.5976e1, 1.5985e1, 1.5992e1, 1.5997e1,
         1.6004e1, 1.6010e1, 1.6014e1, 1.6021e1, 1.6029e1, 1.6033e1, 1.6036e1,
         1.6042e1, 1.6047e1, 1.6054e1, 1.6063e1, 1.6070e1, 1.6077e1, 1.6078e1,
         1.6087e1, 1.6091e1, 1.6096e1, 1.6101e1, 1.6109e1, 1.6114e1, 1.6120e1,
         1.6122e1, 1.6127e1, 1.6131e1, 1.6139e1, 1.6148e1, 1.6156e1, 1.6164e1,
         1.6173e1, 1.6182e1, 1.6190e1, 1.6200e1, 1.6214e1, 1.6222e1, 1.6228e1,
         1.6235e1, 1.6240e1, 1.6243e1, 1.6249e1, 1.6257e1, 1.6272e1, 1.6284e1,
         1.6291e1, 1.6293e1, 1.6297e1, 1.6305e1, 1.6311e1, 1.6315e1, 1.6324e1,
         1.6331e1, 1.6337e1, 1.6342e1, 1.6349e1, 1.6355e1, 1.6360e1, 1.6371e1,
         1.6386e1, 1.6395e1, 1.6413e1, 1.6430e1, 1.6434e1, 1.6437e1, 1.6441e1,
         1.6444e1, 1.6447e1, 1.6451e1, 1.6456e1, 1.6461e1, 1.6465e1, 1.6469e1,
         1.6474e1, 1.6479e1, 1.6483e1, 1.6487e1, 1.6491e1, 1.6493e1, 1.6498e1,
         1.6501e1, 1.6506e1, 1.6523e1, 1.6535e1, 1.6547e1, 1.6556e1, 1.6563e1,
         1.6569e1, 1.6575e1, 1.6581e1, 1.6586e1, 1.6591e1, 1.6598e1, 1.6609e1,
         1.6619e1, 1.6624e1, 1.6627e1, 1.6631e1, 1.6639e1, 1.6646e1, 1.6664e1,
         1.6669e1, 1.6681e1, 1.6692e1, 1.6696e1, 1.6701e1, 1.6708e1, 1.6713e1,
         1.6719e1, 1.6723e1, 1.6725e1, 1.6728e1, 1.6734e1, 1.6739e1, 1.6745e1,
         1.6750e1, 1.6753e1, 1.6757e1, 1.6760e1, 1.6768e1, 1.6787e1, 1.6798e1,
         1.6801e1, 1.6820e1, 1.6824e1, 1.6827e1, 1.6833e1, 1.6836e1, 1.6841e1,
         1.6848e1, 1.6856e1, 1.6862e1, 1.6864e1, 1.6870e1, 1.6878e1, 1.6881e1,
         1.6885e1, 1.6889e1, 1.6892e1, 1.6897e1, 1.6899e1, 1.6902e1, 1.6905e1,
         1.6909e1, 1.6913e1, 1.6916e1, 1.6922e1, 1.6933e1, 1.6936e1, 1.6944e1,
         1.6952e1, 1.6964e1, 1.6969e1, 1.6976e1, 1.6981e1, 1.6986e1, 1.6989e1,
         1.6993e1, 1.6996e1, 1.6998e1, 1.7003e1, 1.7009e1, 1.7021e1, 1.7024e1,
         1.7028e1, 1.7031e1, 1.7035e1, 1.7038e1, 1.7041e1, 1.7044e1, 1.7050e1,
         1.7054e1, 1.7056e1, 1.7059e1, 1.7063e1, 1.7066e1, 1.7071e1, 1.7073e1,
         1.7076e1, 1.7079e1, 1.7083e1, 1.7103e1, 1.7108e1, 1.7112e1, 1.7118e1,
         1.7124e1, 1.7133e1, 1.7143e1, 1.7152e1, 1.7156e1, 1.7161e1, 1.7165e1,
         1.7170e1, 1.7175e1, 1.7177e1, 1.7180e1, 1.7184e1, 1.7188e1, 1.7192e1,
         1.7198e1, 1.7201e1, 1.7206e1, 1.7211e1, 1.7214e1, 1.7225e1, 1.7226e1,
         1.7240e1, 1.7242e1, 1.7244e1, 1.7245e1, 1.7248e1, 1.7251e1, 1.7257e1,
         1.7259e1, 1.7262e1, 1.7264e1, 1.7270e1, 1.7275e1, 1.7281e1, 1.7284e1,
         1.7292e1, 1.7298e1, 1.7302e1, 1.7307e1, 1.7311e1, 1.7317e1, 1.7320e1,
         1.7323e1, 1.7327e1, 1.7330e1, 1.7334e1, 1.7341e1, 1.7347e1, 1.7350e1,
         1.7355e1, 1.7357e1, 1.7360e1, 1.7362e1, 1.7366e1, 1.7371e1, 1.7376e1,
         1.7383e1, 1.7387e1, 1.7390e1, 1.7391e1, 1.7393e1, 1.7397e1, 1.7402e1,
         1.7406e1, 1.7414e1, 1.7420e1, 1.7424e1, 1.7427e1, 1.7430e1, 1.7433e1,
         1.7439e1, 1.7443e1, 1.7445e1, 1.7449e1, 1.7455e1, 1.7459e1, 1.7463e1,
         1.7469e1, 1.7475e1, 1.7482e1, 1.7485e1, 1.7492e1, 1.7494e1, 1.7497e1,
         1.7503e1, 1.7508e1, 1.7512e1, 1.7515e1, 1.7518e1, 1.7524e1, 1.7527e1,
         1.7531e1, 1.7535e1, 1.7538e1, 1.7540e1, 1.7543e1, 1.7548e1, 1.7552e1,
         1.7555e1, 1.7556e1, 1.7559e1, 1.7566e1, 1.7571e1, 1.7576e1, 1.7582e1,
         1.7586e1, 1.7591e1, 1.7593e1, 1.7599e1, 1.7605e1, 1.7610e1, 1.7615e1,
         1.7617e1, 1.7627e1, 1.7631e1, 1.7633e1, 1.7638e1, 1.7643e1, 1.7648e1,
         1.7655e1, 1.7664e1, 1.7671e1, 1.7674e1, 1.7678e1, 1.7686e1, 1.7694e1,
         1.7697e1, 1.7701e1, 1.7707e1, 1.7712e1, 1.7713e1, 1.7716e1, 1.7721e1,
         1.7727e1, 1.7731e1, 1.7733e1, 1.7736e1, 1.7740e1, 1.7745e1, 1.7754e1,
         1.7763e1, 1.7768e1, 1.7772e1, 1.7774e1, 1.7778e1, 1.7781e1, 1.7784e1,
         1.7789e1, 1.7792e1, 1.7795e1, 1.7798e1, 1.7802e1, 1.7808e1, 1.7813e1,
         1.7817e1, 1.7820e1, 1.7828e1, 1.7832e1, 1.7838e1, 1.7842e1, 1.7846e1,
         1.7847e1, 1.7851e1, 1.7853e1, 1.7856e1, 1.7858e1, 1.7861e1, 1.7864e1,
         1.7867e1, 1.7871e1, 1.7874e1, 1.7875e1, 1.7881e1, 1.7888e1, 1.7892e1,
         1.7895e1, 1.7897e1, 1.7901e1, 1.7906e1, 1.7908e1, 1.7911e1, 1.7914e1,
         1.7919e1, 1.7926e1, 1.7931e1, 1.7935e1, 1.7940e1, 1.7942e1, 1.7945e1,
         1.7948e1, 1.7950e1, 1.7956e1, 1.7959e1, 1.7962e1, 1.7965e1, 1.7968e1,
         1.7972e1, 1.7978e1, 1.7981e1, 1.7983e1, 1.7986e1, 1.7989e1, 1.7994e1,
         1.7996e1, 1.7998e1, 1.8002e1, 1.8006e1, 1.8010e1, 1.8012e1, 1.8014e1,
         1.8022e1, 1.8025e1, 1.8028e1, 1.8034e1, 1.8044e1, 1.8047e1, 1.8057e1,
         1.8062e1, 1.8068e1, 1.8072e1, 1.8078e1, 1.8082e1, 1.8091e1, 1.8096e1,
         1.8101e1, 1.8106e1, 1.8119e1, 1.8125e1, 1.8129e1, 1.8138e1, 1.8146e1,
         1.8150e1, 1.8152e1, 1.8156e1, 1.8164e1, 1.8168e1, 1.8172e1, 1.8179e1,
         1.8186e1, 1.8199e1, 1.8220e1, 1.8239e1, 1.8241e1, 1.8245e1, 1.8253e1,
         1.8260e1, 1.8274e1, 1.8277e1, 1.8288e1, 1.8293e1, 1.8294e1, 1.8299e1,
         1.8307e1, 1.8311e1, 1.8324e1, 1.8332e1, 1.8339e1, 1.8342e1, 1.8353e1,
         1.8363e1, 1.8370e1, 1.8379e1, 1.8393e1, 1.8412e1, 1.8419e1, 1.8422e1,
         1.8432e1, 1.8439e1, 1.8444e1, 1.8451e1, 1.8458e1, 1.8459e1, 1.8465e1,
         1.8469e1, 1.8476e1, 1.8489e1, 1.8498e1, 1.8503e1, 1.8513e1, 1.8518e1,
         1.8524e1, 1.8526e1, 1.8530e1, 1.8534e1, 1.8545e1, 1.8551e1, 1.8558e1,
         1.8588e1, 1.8624e1, 1.8629e1, 1.8633e1, 1.8644e1, 1.8649e1, 1.8661e1,
         1.8674e1, 1.8686e1, 1.8697e1, 1.8705e1, 1.8718e1, 1.8730e1, 1.8740e1,
         1.8751e1, 1.8764e1, 1.8771e1, 1.8796e1, 1.8799e1, 1.8806e1, 1.8809e1,
         1.8820e1, 1.8823e1, 1.8831e1, 1.8840e1, 1.8851e1, 1.8855e1, 1.8858e1,
         1.8867e1, 1.8875e1, 1.8890e1, 1.8903e1, 1.8908e1, 1.8919e1, 1.8929e1,
         1.8936e1, 1.8941e1, 1.8949e1, 1.8956e1, 1.8963e1, 1.8969e1, 1.8980e1,
         1.8982e1, 1.8996e1, 1.9006e1, 1.9011e1, 1.9018e1, 1.9024e1, 1.9025e1,
         1.9034e1, 1.9040e1, 1.9047e1, 1.9056e1, 1.9068e1, 1.9073e1, 1.9078e1,
         1.9082e1, 1.9090e1, 1.9097e1, 1.9104e1, 1.9115e1, 1.9121e1, 1.9130e1,
         1.9135e1, 1.9144e1, 1.9155e1, 1.9160e1, 1.9168e1, 1.9173e1, 1.9176e1,
         1.9180e1, 1.9192e1, 1.9198e1, 1.9211e1, 1.9218e1, 1.9224e1, 1.9230e1,
         1.9235e1, 1.9237e1, 1.9242e1, 1.9250e1, 1.9259e1, 1.9261e1, 1.9263e1,
         1.9267e1, 1.9280e1, 1.9285e1, 1.9294e1, 1.9303e1, 1.9308e1, 1.9315e1,
         1.9322e1, 1.9328e1, 1.9339e1, 1.9344e1, 1.9350e1, 1.9357e1, 1.9365e1,
         1.9370e1, 1.9376e1, 1.9387e1, 1.9394e1, 1.9398e1, 1.9403e1, 1.9410e1,
         1.9418e1, 1.9427e1, 1.9431e1, 1.9441e1, 1.9447e1, 1.9459e1, 1.9472e1,
         1.9486e1, 1.9496e1, 1.9510e1, 1.9523e1, 1.9528e1, 1.9539e1, 1.9550e1,
         1.9551e1, 1.9556e1, 1.9574e1, 1.9579e1, 1.9586e1, 1.9589e1, 1.9594e1,
         1.9599e1, 1.9600e1, 1.9612e1, 1.9621e1, 1.9634e1, 1.9636e1, 1.9642e1,
         1.9651e1, 1.9659e1, 1.9665e1, 1.9670e1, 1.9673e1, 1.9679e1, 1.9684e1,
         1.9703e1, 1.9712e1, 1.9718e1, 1.9736e1, 1.9748e1, 1.9771e1, 1.9785e1,
         1.9790e1, 1.9798e1, 1.9806e1, 1.9815e1, 1.9838e1, 1.9863e1, 1.9950e1,
         1.9980e1, 1.9996e1, 2.0005e1, 2.0029e1, 2.0379e1, 2.0696e1, 2.0897e1,
         2.1041e1, 2.1196e1, 2.1455e1, 2.1641e1, 2.2001e1, 2.2248e1, 2.2537e1,
         2.2851e1, 2.3122e1, 2.3521e1, 2.3767e1, 2.3964e1, 2.4344e1, 2.4724e1,
         2.4997e1, 2.5406e1, 2.5708e1, 2.5934e1, 2.6105e1, 2.6530e1, 2.6962e1,
         2.7216e1, 2.7515e1, 2.7862e1, 2.8167e1, 2.8394e1, 2.8659e1, 2.8807e1,
         2.9010e1, 2.9207e1, 2.9644e1, 2.9876e1, 3.0161e1, 3.0601e1, 3.1011e1,
         3.1328e1, 3.1745e1, 3.1979e1, 3.2331e1, 3.2677e1, 3.3097e1, 3.3598e1,
         3.3850e1, 3.4046e1, 3.4328e1, 3.4934e1, 3.5155e1, 3.5376e1, 3.5546e1,
         3.5643e1, 3.5930e1, 3.6160e1, 3.6670e1, 3.7190e1, 3.7700e1, 3.8210e1,
         3.8720e1, 3.9230e1, 3.9740e1, 4.0030e1, 4.1070e1, 4.2100e1, 4.3130e1,
         4.4170e1, 4.5200e1, 4.6230e1, 4.7270e1, 4.8300e1, 4.9330e1, 5.0370e1,
         5.1400e1, 5.2430e1, 5.3470e1, 5.4500e1, 5.5530e1, 5.6570e1, 5.7600e1,
         5.8630e1, 5.9670e1, 6.0700e1, 6.1730e1, 6.2770e1, 6.3800e1, 6.4830e1,
         6.5870e1, 6.6900e1, 6.7930e1, 6.8970e1, 7.0000e1, 7.1030e1, 7.2070e1,
         7.3100e1, 7.4130e1, 7.5170e1, 7.6200e1, 7.7230e1, 7.8270e1, 7.9300e1,
         8.0050e1, 8.2100e1, 8.4150e1, 8.6200e1, 8.8250e1, 9.0300e1, 9.2340e1,
         9.4390e1, 9.6440e1, 9.8490e1, 1.0054e2, 1.0259e2, 1.0464e2, 1.0669e2,
         1.0708e2}};
    constexpr std::array<float, nPacsEntries> yCO2 = {
        {6.7469e-3, 3.4926e-2, 8.8547e-2, 1.7432e-1, 2.7115e-1, 3.6920e-1,
         4.5146e-1, 4.9826e-1, 5.0214e-1, 5.1128e-1, 5.5255e-1, 6.2484e-1,
         7.1291e-1, 7.4200e-1, 7.0101e-1, 6.4783e-1, 5.5338e-1, 4.1268e-1,
         2.7063e-1, 1.7081e-1, 1.0541e-1, 4.8968e-2, 1.6916,    3.2380,
         2.6515,    5.7460,    1.4952e1,  1.5913e1,  3.6168e1,  8.2791e1,
         7.9483e1,  1.1133e2,  6.7176e1,  3.8379e1,  3.4611e1,  1.8162e1,
         1.5189e1,  1.2592e1,  1.0080e1,  2.1587e1,  3.4728e1,  8.6792e1,
         3.1293e1,  2.4304e1,  1.5763e1,  2.0032e1,  2.8903e1,  2.2374e1,
         2.3460e1,  1.6469e1,  2.5926e1,  1.8600e1,  1.9771e1,  1.8012e1,
         2.8306e1,  1.8217e1,  1.7295e1,  1.9177e1,  2.1898e1,  4.2363e1,
         2.1434e1,  2.4488e1,  2.7583e1,  5.4703e1,  3.0300e1,  2.8875e1,
         3.3018e1,  5.3733e1,  3.8119e1,  4.0838e1,  4.9458e1,  7.2686e1,
         4.5436e1,  3.5139e1,  4.5308e1,  6.1881e1,  4.0451e1,  3.8106e1,
         3.0863e1,  3.7724e1,  3.5130e1,  3.7262e1,  5.8689e1,  5.5256e1,
         5.5589e1,  7.1575e1,  5.0729e1,  5.8303e1,  6.2948e1,  6.4704e1,
         7.1442e1,  6.5162e1,  7.2275e1,  6.7545e1,  7.1308e1,  7.0722e1,
         7.6162e1,  7.1933e1,  7.5574e1,  7.6409e1,  7.3687e1,  7.9252e1,
         8.2683e1,  8.1635e1,  8.9543e1,  8.8497e1,  9.0588e1,  8.5500e1,
         8.8018e1,  8.7001e1,  9.2849e1,  8.6631e1,  8.9718e1,  8.5005e1,
         7.4685e1,  8.4108e1,  7.7564e1,  8.0772e1,  8.7758e1,  7.8697e1,
         8.0320e1,  7.5687e1,  7.6945e1,  7.4221e1,  8.0395e1,  8.0962e1,
         8.2951e1,  7.8318e1,  8.0754e1,  7.0513e1,  7.9367e1,  8.2331e1,
         8.0502e1,  7.4285e1,  7.2333e1,  6.7173e1,  6.6359e1,  6.7292e1,
         6.9362e1,  6.2128e1,  7.4962e1,  6.6713e1,  6.5087e1,  6.7725e1,
         6.3011e1,  6.1871e1,  6.3250e1,  6.5768e1,  6.2801e1,  6.0930e1,
         6.1295e1,  5.9465e1,  6.0600e1,  5.8852e1,  5.9460e1,  5.5069e1,
         5.6690e1,  5.5877e1,  5.5874e1,  5.3678e1,  5.1604e1,  5.2659e1,
         5.2535e1,  5.0909e1,  5.1963e1,  5.2408e1,  4.9765e1,  5.0210e1,
         4.9191e1,  4.5738e1,  4.9757e1,  4.7683e1,  4.7804e1,  4.4592e1,
         4.6050e1,  4.2839e1,  4.2268e1,  4.0194e1,  4.1248e1,  4.1935e1,
         3.9290e1,  3.9734e1,  3.6963e1,  3.6717e1,  3.7203e1,  3.4557e1,
         3.1535e1,  3.1777e1,  3.0596e1,  3.1082e1,  3.0021e1,  3.0018e1,
         2.7043e1,  2.7161e1,  2.4708e1,  2.4828e1,  2.3888e1,  2.3884e1,
         2.1800e1,  2.2040e1,  1.9949e1,  1.8220e1,  1.8420e1,  1.7064e1,
         1.7263e1,  1.6357e1,  1.5395e1,  1.4440e1,  1.4111e1,  1.4433e1,
         1.3853e1,  1.3388e1,  1.2921e1,  1.2665e1,  1.3351e1,  1.2899e1,
         1.2893e1,  1.3575e1,  1.2266e1,  1.2260e1,  1.2223e1,  1.2605e1,
         1.5201e1,  1.5500e1,  1.3243e1,  1.2894e1,  1.5167e1,  1.3234e1,
         1.4773e1,  1.5498e1,  1.5474e1,  1.7243e1,  1.7439e1,  1.6051e1,
         1.5187e1,  1.4232e1,  1.4957e1,  1.4505e1,  1.7831e1,  1.8761e1,
         1.7799e1,  1.6823e1,  1.8052e1,  1.8338e1,  1.7997e1,  1.7357e1,
         1.7123e1,  1.7620e1,  1.8659e1,  2.0588e1,  1.9736e1,  1.9288e1,
         1.9591e1,  2.1559e1,  2.1132e1,  2.1123e1,  1.9097e1,  1.8553e1,
         1.8749e1,  2.0197e1,  2.1540e1,  2.0886e1,  2.0759e1,  2.2307e1,
         2.5008e1,  2.4997e1,  2.2875e1,  2.0214e1,  2.0390e1,  2.1836e1,
         2.1411e1,  2.1714e1,  2.4951e1,  2.3784e1,  2.6073e1,  2.5752e1,
         2.6687e1,  2.4134e1,  2.3489e1,  2.2535e1,  2.1553e1,  2.1857e1,
         2.0776e1,  2.0960e1,  2.2831e1,  2.2926e1,  2.6881e1,  2.8660e1,
         2.7705e1,  2.9691e1,  2.9685e1,  3.1146e1,  3.2507e1,  3.8706e1,
         4.5216e1,  3.6583e1,  2.9212e1,  2.2882e1,  2.0652e1,  2.2422e1,
         2.5565e1,  2.5766e1,  2.2590e1,  2.2789e1,  2.3721e1,  2.8621e1,
         2.9654e1,  3.2055e1,  3.2776e1,  4.3281e1,  5.8097e1,  4.7248e1,
         4.3140e1,  2.8504e1,  2.7657e1,  2.7331e1,  2.8896e1,  3.1939e1,
         3.8761e1,  3.5808e1,  2.7695e1,  2.6745e1,  2.6210e1,  2.6832e1,
         2.7136e1,  3.0371e1,  3.0354e1,  3.1392e1,  3.4751e1,  3.6525e1,
         4.0196e1,  5.0180e1,  6.1001e1,  4.9101e1,  4.7832e1,  3.9201e1,
         2.9197e1,  2.7610e1,  2.8964e1,  3.6943e1,  4.4608e1,  3.8074e1,
         3.3759e1,  3.0061e1,  3.0265e1,  2.8362e1,  2.6355e1,  2.8443e1,
         2.8013e1,  2.9159e1,  3.0315e1,  3.0726e1,  3.5135e1,  4.4902e1,
         4.7622e1,  6.6750e1,  5.8742e1,  5.3361e1,  5.8814e1,  7.3735e1,
         8.6971e1,  6.6541e1,  5.2115e1,  4.3165e1,  3.9049e1,  4.3037e1,
         4.7134e1,  4.6283e1,  4.9635e1,  4.3507e1,  4.7588e1,  4.5471e1,
         4.6414e1,  5.1351e1,  4.5131e1,  3.4285e1,  3.2107e1,  3.2069e1,
         3.4440e1,  3.7501e1,  3.7824e1,  2.9555e1,  2.5413e1,  2.2986e1,
         2.2596e1,  2.6306e1,  3.0040e1,  3.5798e1,  4.2928e1,  4.9089e1,
         5.9371e1,  7.6168e1,  6.3801e1,  5.4179e1,  5.4850e1,  6.4091e1,
         8.1573e1,  1.1450e2,  1.7968e2,  2.6407e2,  3.4813e2,  2.7329e2,
         1.0788e2,  5.0215e1,  3.1675e1,  2.2733e1,  1.8601e1,  1.6866e1,
         1.4391e1,  1.6738e1,  1.9778e1,  2.8318e1,  2.8973e1,  3.3409e1,
         4.5397e1,  6.0122e1,  2.1669e1,  1.9249e1,  2.0934e1,  2.1570e1,
         3.0111e1,  2.9403e1,  3.2132e1,  3.0744e1,  1.7327e1,  1.3868e1,
         1.3789e1,  1.5830e1,  1.7494e1,  2.4997e1,  2.6351e1,  2.4616e1,
         3.0078e1,  3.9664e1,  6.4691e1,  2.8642e1,  2.1771e1,  1.8671e1,
         2.0703e1,  1.7940e1,  1.5852e1,  1.6520e1,  2.0622e1,  2.6785e1,
         1.8193e1,  1.4725e1,  1.3963e1,  1.3232e1,  1.4249e1,  1.6570e1,
         1.8958e1,  1.8943e1,  2.2009e1,  2.2339e1,  2.1287e1,  2.8121e1,
         4.8335e1,  3.2526e1,  3.4578e1,  6.3379e1,  2.8000e1,  2.5582e1,
         2.1106e1,  2.3836e1,  3.3430e1,  5.1600e1,  2.9972e1,  2.3098e1,
         2.1025e1,  1.5520e1,  1.5848e1,  1.8576e1,  1.7182e1,  1.9536e1,
         1.5064e1,  1.5033e1,  1.8089e1,  1.8039e1,  1.9046e1,  2.3480e1,
         2.2089e1,  2.4813e1,  3.3380e1,  4.2629e1,  3.4037e1,  2.3393e1,
         1.8912e1,  2.0944e1,  2.8103e1,  2.6374e1,  3.2192e1,  4.4533e1,
         6.4763e1,  4.4161e1,  3.6258e1,  3.8989e1,  4.2397e1,  5.3707e1,
         6.9825e1,  8.4571e1,  8.9357e1,  8.3170e1,  6.6336e1,  6.3925e1,
         4.5725e1,  4.0224e1,  4.3980e1,  3.4085e1,  2.7239e1,  2.8480e1,
         2.0656e1,  2.3869e1,  2.0471e1,  2.8110e1,  1.8336e1,  1.8108e1,
         2.1561e1,  2.1819e1,  2.5272e1,  2.5536e1,  2.4318e1,  2.6048e1,
         3.8321e1,  5.4762e1,  2.3884e1,  1.9494e1,  2.1468e1,  2.2960e1,
         3.0086e1,  2.7647e1,  4.1665e1,  3.9464e1,  2.8484e1,  2.7508e1,
         2.8498e1,  3.0218e1,  2.7534e1,  3.1224e1,  4.2523e1,  3.9344e1,
         2.9793e1,  2.6616e1,  2.9335e1,  3.0578e1,  3.7959e1,  3.9438e1,
         5.8593e1,  3.5569e1,  3.1418e1,  2.5553e1,  2.7285e1,  2.6083e1,
         2.4375e1,  2.6591e1,  4.0341e1,  4.3538e1,  2.0506e1,  1.8324e1,
         2.0799e1,  2.2284e1,  1.8869e1,  1.9122e1,  2.4529e1,  2.7232e1,
         2.8963e1,  1.5987e1,  1.6496e1,  2.0446e1,  1.9235e1,  1.7530e1,
         1.8759e1,  1.9751e1,  2.3442e1,  1.7330e1,  1.9061e1,  1.8845e1,
         2.0095e1,  2.2070e1,  2.2818e1,  2.5528e1,  3.0196e1,  2.3354e1,
         2.7291e1,  3.1958e1,  3.2461e1,  4.2784e1,  5.2359e1,  5.8993e1,
         7.7159e1,  5.1195e1,  3.2587e1,  3.2597e1,  2.5512e1,  2.1842e1,
         2.2345e1,  2.8005e1,  1.9933e1,  1.8231e1,  1.8487e1,  2.0951e1,
         2.2445e1,  2.0497e1,  2.2718e1,  3.2294e1,  3.3773e1,  1.7530e1,
         1.8759e1,  1.9751e1,  2.3442e1,  1.7330e1,  1.9061e1,  1.8845e1,
         2.0095e1,  2.2070e1,  2.2818e1,  2.5528e1,  3.0196e1,  2.3354e1,
         2.7291e1,  3.1958e1,  3.2461e1,  4.2784e1,  5.2359e1,  5.8993e1,
         7.7159e1,  5.1195e1,  3.2587e1,  3.2597e1,  2.5512e1,  2.1842e1,
         2.2345e1,  2.8005e1,  1.9933e1,  1.8231e1,  1.8487e1,  2.0951e1,
         2.2445e1,  2.0497e1,  2.2718e1,  3.2294e1,  3.3773e1,  6.2859e1,
         2.8297e1,  2.1696e1,  2.1964e1,  2.0260e1,  2.1252e1,  2.1752e1,
         2.3238e1,  2.0067e1,  2.1080e1,  2.4547e1,  2.9712e1,  3.7820e1,
         4.3466e1,  4.6420e1,  4.1772e1,  3.0259e1,  2.5620e1,  2.5630e1,
         2.7357e1,  2.8352e1,  3.2043e1,  8.0364e1,  2.5950e1,  2.4494e1,
         2.2300e1,  2.0856e1,  2.2096e1,  2.4572e1,  2.6791e1,  3.4406e1,
         4.0786e1,  4.4722e1,  4.1543e1,  3.4196e1,  3.2245e1,  3.3234e1,
         4.0111e1,  4.5761e1,  6.0730e1,  2.7643e1,  2.3724e1,  2.0558e1,
         2.2051e1,  2.4273e1,  3.1148e1,  3.6059e1,  4.0241e1,  2.8000e1,
         3.0215e1,  3.2433e1,  5.0586e1,  2.2654e1,  2.3415e1,  3.0542e1,
         4.0609e1,  3.3025e1,  3.3277e1,  4.6282e1,  2.5208e1,  2.2763e1,
         2.9649e1,  3.4073e1,  4.3400e1,  3.4340e1,  4.1214e1,  2.4559e1,
         3.2670e1,  3.7092e1,  3.3913e1,  3.3923e1,  2.6331e1,  3.2479e1,
         3.5918e1,  3.4702e1,  2.9567e1,  3.6201e1,  3.2536e1,  3.2662e1,
         3.3942e1,  3.3987e1,  3.6718e1,  3.3283e1,  3.2516e1,  3.2873e1,
         3.2779e1,  3.4525e1,  3.3712e1,  3.5600e1,  3.2992e1,  3.2647e1,
         3.2928e1,  3.4830e1,  3.4906e1,  3.5967e1,  3.3796e1,  3.6040e1,
         3.5633e1,  3.4680e1,  3.7785e1,  3.7127e1,  3.7938e1,  3.8110e1,
         3.9372e1,  3.8029e1,  3.8433e1,  3.6841e1,  3.4029e1,  3.2685e1,
         3.2386e1,  3.2069e1,  3.0691e1,  2.9925e1,  2.9800e1,  2.8018e1,
         2.8173e1,  3.0215e1,  3.0386e1,  3.2069e1,  3.2255e1,  3.2583e1,
         3.2847e1,  3.3204e1,  3.3265e1,  3.3669e1,  3.3448e1,  3.3446e1,
         3.3291e1,  3.3460e1,  3.3410e1,  3.3752e1,  3.3501e1,  3.3419e1,
         3.3181e1,  3.3008e1,  3.3304e1,  3.3020e1,  3.3457e1,  3.2987e1,
         3.3391e1,  3.3530e1,  3.3748e1,  3.3919e1,  3.3715e1,  3.4119e1,
         3.4132e1,  3.3740e1,  3.4098e1,  3.4439e1,  3.4391e1,  3.4609e1,
         3.4436e1,  3.4607e1,  3.4825e1,  3.3604e1,  3.3229e1,  3.3477e1,
         3.3751e1,  3.4352e1,  3.4679e1,  3.4569e1,  3.4988e1,  3.4909e1,
         3.5781e1,  3.9134e1,  3.3215e1,  3.3010e1,  3.2477e1,  2.9759e1,
         3.2269e1,  3.3422e1,  3.3763e1,  3.3839e1,  3.4118e1,  3.4362e1,
         3.4206e1,  3.4767e1,  3.4906e1,  3.5139e1,  3.5372e1,  3.5698e1,
         3.6898e1,  3.4320e1,  3.3305e1,  3.3803e1,  3.4223e1,  3.4346e1,
         3.4468e1,  3.5261e1,  3.5822e1,  3.8208e1,  3.3211e1,  3.2008e1,
         3.0445e1,  3.2629e1,  3.3643e1,  3.4358e1,  3.4545e1,  3.4762e1,
         3.4932e1,  3.5039e1,  3.5755e1,  3.5598e1,  3.3661e1,  3.3832e1,
         3.4050e1,  3.4251e1,  3.4686e1,  3.4888e1,  3.7102e1,  3.1387e1,
         3.3165e1,  3.4117e1,  3.4506e1,  3.4583e1,  3.5237e1,  3.5735e1,
         3.4546e1,  3.4608e1,  3.4996e1,  3.6337e1,  3.1793e1,  3.4553e1,
         3.5177e1,  3.5831e1,  3.5408e1,  3.4923e1,  3.4564e1,  3.6061e1,
         3.2953e1,  3.6072e1,  3.5228e1,  3.4898e1,  3.5381e1,  3.4334e1,
         3.3273e1,  3.4396e1,  3.4956e1,  3.4720e1,  3.4439e1,  3.3938e1,
         3.4671e1,  3.5043e1,  3.4278e1,  3.4994e1,  3.4228e1,  3.4991e1,
         3.4474e1,  3.5082e1,  3.4831e1,  3.4829e1,  3.5000e1,  3.4748e1,
         3.4935e1,  3.5121e1,  3.4900e1,  3.5212e1,  3.4788e1,  3.4708e1,
         3.4380e1,  3.4644e1,  3.4721e1,  3.5094e1,  3.4873e1,  3.5044e1,
         3.5121e1,  3.5026e1,  3.5023e1,  3.5442e1,  3.4909e1,  3.4939e1,
         3.5170e1,  3.5058e1,  3.5307e1,  3.5429e1,  3.5271e1,  3.5131e1,
         3.5207e1,  3.5266e1,  3.5468e1,  3.5295e1,  3.5170e1,  3.5465e1,
         3.5152e1,  3.5308e1,  3.5462e1,  3.5303e1,  3.5270e1,  3.5410e1,
         3.5299e1,  3.5501e1,  3.5344e1,  3.5467e1,  3.5466e1,  3.5544e1,
         3.5371e1,  3.5432e1,  3.5413e1,  3.5208e1,  3.5472e1,  3.5469e1,
         3.5592e1,  3.5494e1,  3.5616e1,  3.5709e1,  3.5692e1,  3.5534e1,
         3.5625e1,  3.5606e1,  3.5695e1,  3.5756e1,  3.5907e1,  3.5763e1,
         3.5949e1,  3.6191e1,  3.6527e1,  3.6718e1,  3.6835e1,  3.6766e1,
         3.6808e1,  3.6551e1,  3.6448e1,  3.5802e1,  3.5369e1,  3.4774e1,
         3.4137e1,  3.3475e1,  3.2583e1,  3.1921e1,  3.1590e1,  3.0961e1,
         3.0553e1,  3.0280e1,  3.0091e1,  2.9903e1,  2.9996e1,  2.9918e1,
         3.0145e1,  3.0421e1,  3.0251e1,  2.9826e1,  2.9385e1,  2.9171e1,
         2.8874e1,  2.8653e1,  2.8711e1,  2.8575e1,  2.8651e1,  2.8377e1,
         2.8123e1,  2.7910e1,  2.8035e1,  2.7974e1,  2.7803e1,  2.7311e1,
         2.7158e1,  2.7478e1,  2.7468e1,  2.7069e1,  2.6542e1,  2.6389e1,
         2.6601e1,  2.6278e1,  2.6098e1,  2.6165e1,  2.5834e1,  2.5504e1,
         2.5986e1,  2.5393e1,  2.4404e1,  2.4324e1,  2.4053e1,  2.4018e1,
         2.3543e1,  2.3169e1,  2.2050e1,  2.1980e1,  2.1330e1,  2.0138e1,
         1.9736e1,  1.8710e1,  1.7774e1,  1.7188e1,  1.6509e1,  1.6092e1,
         1.5639e1,  1.5287e1,  1.5027e1,  1.4982e1,  1.4584e1,  1.4550e1,
         1.4208e1,  1.3968e1,  1.3637e1,  1.3304e1,  1.3304e1,  1.2592e1,
         1.2326e1,  1.1842e1,  1.1426e1,  1.1079e1,  1.0592e1,  1.0070e1,
         9.8707,    9.4744,    9.1585,    8.9229,    8.6291,    8.3000,
         8.1328,    7.8260,    7.6232,    7.3619,    7.3330,    6.9313,
         6.8787,    6.6611,    6.3447,    6.0507,    5.8142,    5.5418,
         5.3038,    5.0295,    4.8488,    4.6202,    4.4264,    4.2438,
         4.0606,    3.8530,    3.7162,    3.6875}};

    // Photoionization yield
    /*
    constexpr size_t nYieldEntries = 11;
    constexpr std::array<float, nYieldEntries> xIon = {{
      12.65, 12.87, 13.02, 13.24, 13.88,
      14.66, 15.01, 15.44, 15.67, 15.87,
      16.22}};

    constexpr std::array<float, nYieldEntries> yIon = {{
      0.,     0.01226, 0.02900, 0.08853, 0.3693,
      0.7024, 0.8190,  0.9262,  0.9715,  0.9883,
      1.}};
    //*/

    constexpr size_t nYieldEntries = 405;
    constexpr std::array<float, nYieldEntries> xIon = {
        {13.6926361811117,   13.715317754199855, 13.744304479209204,
         13.763071315347828, 13.769719353658544, 13.7850365564675,
         13.798269318989469, 13.804269586746194, 13.808694970264064,
         13.816955562862878, 13.8212884738047,   13.831848790626944,
         13.835934738154664, 13.844799801836533, 13.855052054429185,
         13.8595526681464,   13.867831582521367, 13.876406771550556,
         13.888980843356499, 13.899961542200646, 13.9101375916142,
         13.920963901562597, 13.940345759722771, 13.95133595914033,
         13.959841076442459, 13.9706718790712,   13.985592295043665,
         14.003003612403177, 14.020194360285029, 14.033324173840148,
         14.0440634913440,   14.052814278658353, 14.063568782625623,
         14.081174116971813, 14.096347169051427, 14.1030392906901,
         14.1116853027492,   14.127162124690432, 14.146809499131525,
         14.164549875168559, 14.1776814839775,   14.204425032592868,
         14.22203833858442,  14.242223403408707, 14.262207444361881,
         14.3114976043571,   14.336354545664648, 14.370324777846296,
         14.402088253874295, 14.424916068977673, 14.4455879628798,
         14.459261593089842, 14.482223621392002, 14.486952919954708,
         14.500706026036182, 14.5261306957798,   14.540225865717755,
         14.55167593261424,  14.579675899274896, 14.598328114122056,
         14.6217975979017,   14.649988008640532, 14.668949973983407,
         14.68543186918539,  14.704581675247962, 14.7115409666837,
         14.72583717007484,  14.732865794260709, 14.742723142987813,
         14.756851709531364, 14.7654306908545,   14.784392635740517,
         14.803402461824746, 14.825188204182082, 14.852510498743328,
         14.8799338658639,   14.907458508938598, 14.926787234711002,
         14.951710912274615, 14.97671886513848,  14.9962266406587,
         15.021382942869986, 15.052245178882915, 15.080411593273755,
         15.086058448195018, 15.1058522900559,   15.13137804560613,
         15.139905996793697, 15.15129217973719,  15.165548180153339,
         15.1798308472062,   15.21134846614213,  15.237232118158476,
         15.257426038074007, 15.292167356428761, 15.3212398888427,
         15.350422983597124, 15.379717463370714, 15.397348455279328,
         15.420918846520996, 15.4653081279398,   15.492065192480576,
         15.506969993254085, 15.566876709368936, 15.597003977621084,
         15.6302796380464,   15.648489930834549, 15.694200952661875,
         15.712560781595407, 15.734033950003656, 15.7555658902412,
         15.777158249290967, 15.832951722369646, 15.864118716875518,
         15.882878287973838, 15.9016812588367,   15.933119695983626,
         15.964683923587197, 15.986852428274682, 16.012263694198257,
         16.0441413442444,   16.060127917879381, 16.085772848771978,
         16.108279153159383, 16.124393652112783, 16.1437744174517,
         16.169687394214922, 16.192429294057543, 16.205454317863843,
         16.254482043806203, 16.2708907514474,   16.287332621358544,
         16.303807539780127, 16.315258834593077, 16.336731639023082,
         16.3515521858660,   16.358101759845479, 16.366462948094021,
         16.377990558446815, 16.401341034343169, 16.4263878538541,
         16.441480606508204, 16.446461694187914, 16.454920028913499,
         16.488579820014948, 16.5018712548574,   16.510207069598721,
         16.525350792108942, 16.538910304310718, 16.549124978357099,
         16.5593710768857,   16.574552430482015, 16.583195854842472,
         16.589697937605283, 16.59989678448029,  16.6170759075614,
         16.623891673652899, 16.63250208278615,  16.642555936157301,
         16.649499048833651, 16.6545414460324,   16.666536166194199,
         16.677007621494056, 16.685720088052197, 16.694294651031189,
         16.7028643051852,   16.71151709423151,  16.72214440164722,
         16.726912709204488, 16.735623420268325, 16.7406326848921,
         16.756388867163764, 16.763165979189449, 16.768523988157806,
         16.775397853052805, 16.7840525866527,   16.79626923621699,
         16.806843340599176, 16.822564226874647, 16.833111369418571,
         16.8417710943501,   16.856150452556832, 16.863090856364984,
         16.870379005209315, 16.878793800563464, 16.8822826164003,
         16.900106097952754, 16.901668333264944, 16.908630828884668,
         16.914035866835025, 16.9227113987917,   16.929835266035678,
         16.937079430584298, 16.942326026551164, 16.947738268400819,
         16.9600981718265,   16.972585316979409, 16.976215059284918,
         16.983308911603206, 16.99248626983157,  16.9975610223128,
         17.006390819013841, 17.013489840173118, 17.022377564427835,
         17.037045572946376, 17.0439771482640,   17.05862796908082,
         17.072896330056992, 17.07996040663712,  17.087161263055631,
         17.0960987995421,   17.108774339166423, 17.109921325176312,
         17.116887762599134, 17.122003762767974, 17.1306947067649,
         17.139291886939795, 17.149805689502621, 17.149840560978209,
         17.170771924499299, 17.1863410555122,   17.190001558809126,
         17.195222653072335, 17.209252575134954, 17.221481499655745,
         17.2250710772106,   17.244393331080449, 17.253101919045502,
         17.269030517088712, 17.286683255823412, 17.2938325195936,
         17.31153602691003,  17.325638323826517, 17.331082417868089,
         17.343525193183435, 17.3507084485495,   17.359529393428549,
         17.363169218091368, 17.381044524564135, 17.395325993369461,
         17.4078837058457,   17.42219709193596,  17.434850524623741,
         17.445634443710716, 17.460005576934108, 17.4673201150134,
         17.476381749154598, 17.4817782834958,   17.487250172437648,
         17.49623300058105,  17.5071713755285,   17.51805239832078,
         17.527076074953754, 17.534380470084969, 17.544972583620215,
         17.5507586350134,   17.558088754575344, 17.569068284746468,
         17.578182490082916, 17.591010438322844, 17.5982765578418,
         17.602037191094372, 17.614872213380817, 17.618577101404959,
         17.631388876773816, 17.6406645052905,   17.642460300152862,
         17.657229846818353, 17.668290450846513, 17.668319657477721,
         17.6831156531875,   17.692305681783655, 17.703171157414861,
         17.704869975135313, 17.707140124676567, 17.7164941299739,
         17.731347879301854, 17.746278882303425, 17.757502739233423,
         17.764901226305451, 17.7799168619820,   17.794849101393172,
         17.796551510833392, 17.802053810070653, 17.804256909769734,
         17.8155573196525,   17.83247317248081,  17.849378779102384,
         17.858731420683647, 17.864251650597762, 17.8701781210926,
         17.879679950698399, 17.896668766429517, 17.904213688458377,
         17.909719647821234, 17.9118972061763,   17.92141367425744,
         17.930889432760015, 17.934655561735916, 17.940221537906154,
         17.9442325932283,   17.957490809737994, 17.965048847188484,
         17.996431596525216, 18.009856559203229, 18.0234870647004,
         18.030175678630584, 18.043750312681148, 18.060636813330966,
         18.073792596638107, 18.0875216722023,   18.107797009254504,
         18.10794696102213,  18.138676710166688, 18.169523716198462,
         18.2038765497646,   18.207221333083496, 18.234787137527469,
         18.248740764761383, 18.283413767908357, 18.2937572951645,
         18.304304126360453, 18.339117453498947, 18.360264789676901,
         18.377735854631954, 18.3882447714001,   18.402395823445683,
         18.42685476474664,  18.448107600411063, 18.451849751240893,
         18.4659611173178,   18.494284563491945, 18.501484056913529,
         18.529896170031929, 18.551419973762375, 18.5728102112595,
         18.597997113167047, 18.616068554852362, 18.637627272675577,
         18.670323273006566, 18.6847385286699,   18.706590746348422,
         18.743032545641412, 18.753937415004341, 18.761328316806427,
         18.7796251381450,   18.797922911201226, 18.820101965749092,
         18.838471869249318, 18.845787766087263, 18.8642899589054,
         18.882795444814064, 18.908918372131144, 18.927435570696847,
         18.949921476340204, 18.9722199075076,   18.987305937776732,
         19.002296862380263, 19.009705021449719, 19.032379930397511,
         19.0435671513016,   19.055067704685875, 19.077641427979369,
         19.104146784358008, 19.123098952545011, 19.1269990033299,
         19.145967883241649, 19.168905801975601, 19.207172650806701,
         19.218750171154536, 19.2340194170205,   19.257075909461317,
         19.261018237761306, 19.292003573712663, 19.295740094261259,
         19.3152011802390,   19.334523066428019, 19.354005400928973,
         19.365775184256258, 19.385191162600915, 19.4048128455129,
         19.420405455491156, 19.43614014335493,  19.471627716250396,
         19.479378562200313, 19.5071063895351,   19.546701405484413,
         19.598562895316689, 19.626403888478372, 19.646524645276187,
         19.7029013943660,   19.706871463391909, 19.747341872030784,
         19.763520917003543, 19.783991501058271, 19.8001706011875,
         19.861503694771521, 19.898480975465262, 19.919154152807984,
         19.939735002832577, 19.9853971171303,   20.018636744916986,
         20.043637577493911, 20.068786367947979, 20.089685885252269}};
    constexpr std::array<float, nYieldEntries> yIon = {
        {0.02808, 0.03070, 0.03609, 0.05291, 0.13500, 0.28217, 0.42368, 0.36980,
         0.41792, 0.39518, 0.42347, 0.43754, 0.41483, 0.50541, 0.45149, 0.5081,
         0.47687, 0.50228, 0.47951, 0.55589, 0.47082, 0.51038, 0.55269, 0.61491,
         0.60634, 0.63174, 0.61461, 0.65694, 0.64829, 0.68217, 0.66791, 0.68483,
         0.66773, 0.71007, 0.69577, 0.72404, 0.70697, 0.73799, 0.72082, 0.74899,
         0.73188, 0.77414, 0.75132, 0.78514, 0.77081, 0.77322, 0.79000, 0.80104,
         0.79511, 0.80058, 0.81740, 0.80312, 0.80010, 0.82272, 0.80844, 0.80823,
         0.84210, 0.81368, 0.82478, 0.81896, 0.82727, 0.82420, 0.84104, 0.82958,
         0.86342, 0.83503, 0.84058, 0.82070, 0.87727, 0.84316, 0.86416, 0.86705,
         0.86994, 0.86127, 0.88439, 0.86705, 0.87283, 0.86416, 0.86705, 0.81214,
         0.84971, 0.85838, 0.83237, 0.76879, 0.80058, 0.74855, 0.79480, 0.77168,
         0.79191, 0.76012, 0.77746, 0.70520, 0.70231, 0.72543, 0.70520, 0.72832,
         0.66763, 0.71387, 0.72832, 0.68497, 0.67341, 0.73410, 0.75434, 0.66474,
         0.73699, 0.74855, 0.76879, 0.70231, 0.74855, 0.80347, 0.79191, 0.80925,
         0.71387, 0.77457, 0.81214, 0.78902, 0.81214, 0.76590, 0.79769, 0.77746,
         0.86127, 0.84104, 0.87572, 0.88728, 0.86416, 0.86705, 0.97977, 0.93353,
         0.94220, 0.93642, 0.88439, 0.90462, 0.95087, 0.94947, 0.92132, 0.94030,
         0.97179, 0.92783, 0.96251, 0.90921, 0.87480, 0.84032, 0.85608, 0.80897,
         0.74946, 0.82818, 0.86912, 0.88495, 0.86303, 0.83166, 0.79085, 0.83184,
         0.75957, 0.90427, 0.91064, 0.84786, 0.85420, 0.82282, 0.92352, 0.87954,
         0.92675, 0.93312, 0.85457, 0.80118, 0.81696, 0.83903, 0.82651, 0.70080,
         0.89895, 0.87071, 0.95879, 0.88658, 0.96524, 0.89609, 0.93388, 0.95595,
         0.9466,  0.89636, 0.89961, 0.87767, 0.92490, 0.76462, 0.80555, 0.68610,
         0.86541, 0.88115, 0.79322, 0.88758, 0.93479, 0.88766, 0.96634, 0.94752,
         0.87524, 0.90987, 0.86902, 0.90370, 0.88806, 0.85664, 0.87241, 0.75297,
         0.88194, 0.92917, 0.95437, 0.98273, 0.83189, 0.94514, 0.81945, 0.87930,
         0.94538, 0.95172, 0.99266, 0.98331, 0.97803, 1.00955, 0.92121, 0.93064,
         0.83913, 0.91165, 0.94635, 0.9589,  0.80743, 0.96830, 0.93989, 0.95562,
         0.9051,  0.98080, 0.96181, 0.86714, 0.92072, 0.90173, 0.97111, 0.95213,
         0.85429, 0.96153, 0.94887, 1.00563, 0.91411, 0.98350, 0.99291, 0.95816,
         0.96759, 0.92022, 0.98327, 0.96431, 0.91379, 1.0021,  1.02730, 0.99889,
         1.03989, 0.97046, 1.02720, 1.01455, 0.95459, 0.9798,  0.66431, 0.96397,
         0.99550, 1.01754, 0.99228, 1.00486, 0.94490, 1.03321, 1.02055, 1.04893,
         0.99211, 1.05833, 1.01416, 1.02988, 1.01092, 1.03931, 1.03927, 0.97299,
         0.73321, 0.58809, 0.97295, 1.03601, 1.01388, 1.04223, 1.07058, 1.00431,
         1.05789, 1.01053, 0.85279, 0.73921, 1.03889, 1.0704,  1.06089, 1.01352,
         0.93778, 0.80527, 1.03869, 1.07967, 1.02599, 0.98811, 0.81775, 1.07011,
         1.0827,  1.05112, 1.01326, 0.88075, 1.06054, 0.97533, 0.90275, 0.89778,
         0.90746, 0.88489, 0.89672, 0.88920, 0.89889, 0.97094, 0.94837, 0.97526,
         0.94945, 0.95055, 0.94949, 0.95596, 0.97317, 0.98179, 0.96244, 0.96568,
         0.98074, 0.96355, 0.97862, 0.95498, 0.96681, 0.97220, 0.95930, 0.99587,
         0.98836, 0.95503, 0.96471, 0.97871, 0.96473, 0.98195, 0.96906, 0.98628,
         0.97876, 0.96695, 0.98094, 0.95945, 0.97451, 0.967,   0.96917, 0.97885,
         0.96703, 0.97026, 0.97887, 0.96168, 0.97137, 0.98212, 0.97891, 0.98107,
         0.95958, 0.97357, 0.95637, 0.97682, 0.96069, 0.96285, 0.97899, 0.96287,
         0.98115, 0.95320, 0.96934, 0.97258, 0.97905, 0.96399, 0.97476, 0.96832,
         0.97049, 0.96082, 0.97695, 0.98449, 0.97159, 0.95978, 0.98021, 0.96732,
         0.98130, 0.97701, 0.96519, 0.98026, 0.97059, 0.98242, 0.97706, 0.96632,
         0.98675, 0.97602, 0.98356, 0.97176, 0.99435, 0.98361, 0.97934, 0.98902,
         0.98796, 0.99550, 0.97508, 0.99121, 0.99124, 0.99234, 0.98267, 0.99236,
         0.98055, 0.98594, 0.99026, 0.98274, 0.99135}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xCO2, yCO2, e);

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    return true;
  }

  if (e >= 290.06 && e <= 341.3) {
    // Carbon K edge

    constexpr size_t nEntries = 46;
    constexpr std::array<float, nEntries> xCO2 = {
        {2.8967e2, 2.9006e2, 2.9036e2, 2.9071e2, 2.9105e2, 2.9132e2, 2.9175e2,
         2.9194e2, 2.9213e2, 2.9217e2, 2.9247e2, 2.9286e2, 2.9336e2, 2.9366e2,
         2.9397e2, 2.9466e2, 2.9547e2, 2.9601e2, 2.9631e2, 2.9697e2, 2.9793e2,
         2.9904e2, 3.0031e2, 3.0153e2, 3.0284e2, 3.0384e2, 3.0453e2, 3.0560e2,
         3.0698e2, 3.0852e2, 3.1002e2, 3.1128e2, 3.1224e2, 3.1328e2, 3.1424e2,
         3.1539e2, 3.1650e2, 3.1785e2, 3.1996e2, 3.2245e2, 3.2545e2, 3.2875e2,
         3.3193e2, 3.3593e2, 3.3904e2, 3.4134e2}};
    constexpr std::array<float, nEntries> yCO2 = {
        {1.4893,    2.8017,    4.1009,    1.0011e1,  1.1982e1,  1.0011e1,
         4.1395,    2.7813,    1.4556,    1.1096,    9.7879e-1, 1.0178,
         1.2919,    1.0045,    8.9979e-1, 8.3420e-1, 1.0755,    8.2710e-1,
         8.2697e-1, 9.1158e-1, 8.7852e-1, 9.9558e-1, 1.0146,    1.1904,
         1.2225,    1.4115,    1.4308,    1.3454,    1.3840,    1.5465,
         1.7548,    1.9437,    2.0021,    1.9298,    1.9294,    1.8048,
         1.6476,    1.5034,    1.3458,    1.2077,    1.0823,    9.7640e-1,
         9.0974e-1, 8.6233e-1, 8.5447e-1, 8.4696e-1}};
    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xCO2, yCO2, e);
    eta = 1.;
    return true;
  }

  if (e >= 524.9 && e <= 572.8) {
    // Oxygen K edge

    constexpr size_t nEntries = 44;
    constexpr std::array<float, nEntries> xCO2 = {
        {5.2490e2, 5.2490e2, 5.2954e2, 5.3096e2, 5.3214e2, 5.3282e2, 5.3319e2,
         5.3373e2, 5.3448e2, 5.3503e2, 5.3526e2, 5.3561e2, 5.3604e2, 5.3642e2,
         5.3691e2, 5.3717e2, 5.3743e2, 5.3774e2, 5.3812e2, 5.3851e2, 5.3904e2,
         5.3996e2, 5.4084e2, 5.4226e2, 5.4403e2, 5.4568e2, 5.4725e2, 5.4855e2,
         5.4920e2, 5.5054e2, 5.5245e2, 5.5360e2, 5.5567e2, 5.5693e2, 5.5781e2,
         5.5835e2, 5.5938e2, 5.6007e2, 5.6080e2, 5.6292e2, 5.6495e2, 5.6760e2,
         5.7009e2, 5.7280e2}};
    constexpr std::array<float, nEntries> yCO2 = {
        {3.0446e-1, 3.4889e-1, 3.7017e-1, 4.1350e-1, 5.2302e-1, 7.3175e-1,
         2.5744,    4.7866,    2.9776,    1.2349,    1.0929,    1.0079,
         9.5595e-1, 9.8459e-1, 1.2643,    1.4918,    1.5629,    1.5630,
         1.5253,    1.5350,    1.6016,    1.6494,    1.6072,    1.4753,
         1.3815,    1.3633,    1.4162,    1.3931,    1.4124,    1.5268,
         1.7456,    1.7982,    1.7992,    1.8709,    1.9045,    1.8858,
         1.8059,    1.7493,    1.6787,    1.5471,    1.4581,    1.3978,
         1.3659,    1.3389}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xCO2, yCO2, e);
    eta = 1.;
    return true;
  }

  double a, b, c, d;
  if (e < 290) {
    a = -20.1699;
    b = 1244.259;
    c = -11489.;
    d = 36074.58;
  } else if (e < 524.9) {
    a = 37.50509;
    b = -429.43;
    c = 65138.77;
    d = -902421.;
  } else if (e < 2293.2) {
    a = 0.731716;
    b = 19329.84;
    c = -472016.;
    d = 4458877.;
  } else {
    a = -4.33101;
    b = 19022.22;
    c = 161688.6;
    d = -71331572.;
  }

  const double f = Evaluate(ip / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsMethane(const double e, double& cs,
                                           double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109
  // Photoionization yield:
  // K. Kameta et al., J. El. Spectr. Rel. Phen. 123 (2002), 225-238

  if (e < 8.61) {
    cs = eta = 0.;
    return true;
  }

  if (e < 150.) {
    // Photoabsorption cross-section
    constexpr size_t nPacsEntries = 134;
    constexpr std::array<float, nPacsEntries> xCH4 = {
        {8.6100,    9.0000,    9.2130,    9.5000,    9.6900,    1.0050e01,
         1.0425e01, 1.0700e01, 1.0913e01, 1.1270e01, 1.1500e01, 1.1713e01,
         1.1900e01, 1.2125e01, 1.2375e01, 1.2610e01, 1.3000e01, 1.3325e01,
         1.3620e01, 1.4000e01, 1.4500e01, 1.5000e01, 1.5500e01, 1.6000e01,
         1.6500e01, 1.7000e01, 1.7500e01, 1.8000e01, 1.8500e01, 1.9000e01,
         1.9500e01, 2.0000e01, 2.0500e01, 2.1000e01, 2.1500e01, 2.2000e01,
         2.2500e01, 2.3000e01, 2.3500e01, 2.4000e01, 2.4500e01, 2.5000e01,
         2.5500e01, 2.6000e01, 2.6500e01, 2.7000e01, 2.7500e01, 2.8000e01,
         2.8500e01, 2.9000e01, 2.9500e01, 3.0000e01, 3.0500e01, 3.1000e01,
         3.1500e01, 3.2000e01, 3.2500e01, 3.3000e01, 3.3500e01, 3.4000e01,
         3.4500e01, 3.5000e01, 3.5500e01, 3.6000e01, 3.6500e01, 3.7000e01,
         3.7500e01, 3.8000e01, 3.8500e01, 3.9000e01, 3.9500e01, 4.0000e01,
         4.1000e01, 4.2000e01, 4.3000e01, 4.4000e01, 4.5000e01, 4.6000e01,
         4.7000e01, 4.8000e01, 4.9000e01, 5.0000e01, 5.1000e01, 5.2000e01,
         5.3000e01, 5.4000e01, 5.5000e01, 5.6000e01, 5.7000e01, 5.8000e01,
         5.9000e01, 6.0000e01, 6.1000e01, 6.2000e01, 6.3000e01, 6.4000e01,
         6.5000e01, 6.6000e01, 6.7000e01, 6.8000e01, 6.9000e01, 7.0000e01,
         7.1000e01, 7.2000e01, 7.3000e01, 7.4000e01, 7.5000e01, 7.6000e01,
         7.7000e01, 7.8000e01, 7.9000e01, 8.0000e01, 8.2000e01, 8.4000e01,
         8.6000e01, 8.8000e01, 9.0000e01, 9.2000e01, 9.4000e01, 9.6000e01,
         9.8000e01, 1.0000e02, 1.0200e02, 1.0400e02, 1.0600e02, 1.0800e02,
         1.1000e02, 1.1200e02, 1.1270e02, 1.1900e02, 1.2500e02, 1.3291e02,
         1.4286e02, 1.5000e02}};
    constexpr std::array<float, nPacsEntries> yCH4 = {
        {0.,        3.9896,    9.2248,    1.6727e01, 1.8644e01, 1.7399e01,
         1.9316e01, 1.8119e01, 1.6679e01, 2.0792e01, 2.8706e01, 3.0086e01,
         2.9689e01, 3.1516e01, 3.3929e01, 3.9598e01, 4.5208e01, 4.8369e01,
         4.9053e01, 4.9090e01, 4.8742e01, 4.8255e01, 4.7111e01, 4.5877e01,
         4.4643e01, 4.3260e01, 4.1429e01, 3.9947e01, 3.8415e01, 3.6982e01,
         3.5649e01, 3.4355e01, 3.2674e01, 3.1480e01, 3.0296e01, 2.9152e01,
         2.7719e01, 2.6535e01, 2.5441e01, 2.4306e01, 2.3001e01, 2.1999e01,
         2.1576e01, 2.0181e01, 1.9134e01, 1.8481e01, 1.7642e01, 1.6825e01,
         1.5854e01, 1.5364e01, 1.4885e01, 1.4252e01, 1.3609e01, 1.3217e01,
         1.2200e01, 1.1381e01, 1.0879e01, 1.0716e01, 1.0269e01, 1.0040e01,
         9.5267,    9.0567,    8.8718,    8.4345,    8.1288,    7.9107,
         7.6596,    7.4084,    6.9486,    6.9827,    6.6434,    6.4139,
         6.0315,    5.6927,    5.2109,    4.9047,    4.6753,    4.3687,
         4.1610,    3.9201,    3.8223,    3.5040,    3.3288,    3.1755,
         3.0000,    2.8907,    2.6709,    2.4951,    2.4076,    2.3200,
         2.1771,    2.0452,    2.0237,    1.9248,    1.8701,    1.7600,
         1.6499,    1.6283,    1.5623,    1.4520,    1.4303,    1.3975,
         1.3868,    1.2652,    1.2101,    1.1772,    1.1220,    1.0890,
         1.0449,    1.0230,    9.8999e-1, 9.4580e-1, 9.0188e-1, 8.2448e-1,
         7.8041e-1, 7.3630e-1, 6.9212e-1, 6.4789e-1, 6.2595e-1, 5.8161e-1,
         5.5961e-1, 5.2637e-1, 5.1550e-1, 4.8219e-1, 4.7128e-1, 4.4913e-1,
         4.2695e-1, 4.0474e-1, 3.8734e-1, 3.4841e-1, 3.0851e-1, 2.7834e-1,
         2.3357e-1, 2.0263e-1}};

    // Photoionization yield
    constexpr size_t nYieldEntries = 51;
    constexpr std::array<float, nYieldEntries> xIon = {
        {12.05,   12.5833, 12.7333, 12.8167, 12.9167, 13.0167, 13.0833, 13.1833,
         13.2833, 13.3833, 13.4667, 13.6,    13.6833, 13.75,   13.8167, 13.9333,
         14.0167, 14.1,    14.2167, 14.2667, 14.3667, 14.5,    14.65,   14.7833,
         14.8667, 14.9833, 15.1667, 15.3167, 15.4333, 15.6833, 16.05,   16.0833,
         16.2167, 16.4167, 16.7333, 16.95,   18.35,   19.7833, 20.1833, 20.35,
         20.4667, 20.6,    21.1833, 21.4,    21.5167, 21.65,   22.1167, 22.8667,
         23.35,   23.75,   24.1333}};
    constexpr std::array<float, nYieldEntries> yIon = {
        {0.,       0.,      0.0017271, 0.0069085, 0.01209, 0.022453, 0.039724,
         0.063903, 0.10708, 0.15717,   0.18653,   0.23661, 0.27288,  0.30225,
         0.33333,  0.37478, 0.39896,   0.43005,   0.4715,  0.49223,  0.55095,
         0.59931,  0.66839, 0.72539,   0.75648,   0.7962,  0.84629,  0.88428,
         0.90846,  0.95164, 0.99309,   1.,        1.,      1.,       1.,
         1.,       1.,      0.99482,   0.97927,   0.98446, 0.97755,  0.98446,
         0.97927,  0.98964, 0.97927,   0.98618,   0.97927, 0.981,    0.98791,
         1.,       1.}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xCH4, yCH4, e);

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    return true;
  }

  if (e >= 285. && e <= 340.) {
    // Carbon K edge

    constexpr size_t nEntries = 106;
    constexpr std::array<float, nEntries> xCH4 = {
        {2.8500e02, 2.8591e02, 2.8640e02, 2.8671e02, 2.8695e02, 2.8701e02,
         2.8704e02, 2.8708e02, 2.8712e02, 2.8716e02, 2.8725e02, 2.8734e02,
         2.8739e02, 2.8759e02, 2.8768e02, 2.8776e02, 2.8781e02, 2.8786e02,
         2.8790e02, 2.8793e02, 2.8795e02, 2.8798e02, 2.8801e02, 2.8803e02,
         2.8805e02, 2.8808e02, 2.8810e02, 2.8812e02, 2.8815e02, 2.8817e02,
         2.8823e02, 2.8827e02, 2.8832e02, 2.8836e02, 2.8839e02, 2.8843e02,
         2.8849e02, 2.8853e02, 2.8855e02, 2.8860e02, 2.8865e02, 2.8868e02,
         2.8876e02, 2.8881e02, 2.8883e02, 2.8888e02, 2.8894e02, 2.8901e02,
         2.8908e02, 2.8912e02, 2.8920e02, 2.8926e02, 2.8933e02, 2.8936e02,
         2.8941e02, 2.8944e02, 2.8949e02, 2.8952e02, 2.8956e02, 2.8958e02,
         2.8964e02, 2.8968e02, 2.8971e02, 2.8975e02, 2.8979e02, 2.8984e02,
         2.8989e02, 2.8993e02, 2.8996e02, 2.9003e02, 2.9011e02, 2.9015e02,
         2.9018e02, 2.9022e02, 2.9026e02, 2.9029e02, 2.9034e02, 2.9037e02,
         2.9048e02, 2.9054e02, 2.9063e02, 2.9071e02, 2.9076e02, 2.9085e02,
         2.9103e02, 2.9126e02, 2.9150e02, 2.9223e02, 2.9366e02, 2.9590e02,
         2.9776e02, 3.0025e02, 3.0224e02, 3.0342e02, 3.0479e02, 3.0628e02,
         3.0821e02, 3.0908e02, 3.1120e02, 3.1275e02, 3.1580e02, 3.1934e02,
         3.2451e02, 3.2961e02, 3.3495e02, 3.4000e02}};
    constexpr std::array<float, nEntries> yCH4 = {
        {4.1692e-02, 8.4191e-02, 1.5756e-01, 3.8643e-01, 5.0083e-01, 1.0526,
         1.2561,     1.0539,     7.0664e-01, 4.1755e-01, 3.3202e-01, 3.6272e-01,
         4.7949e-01, 4.5392e-01, 5.7151e-01, 7.7579e-01, 1.1537,     1.8502,
         3.1844,     6.1130,     1.0201e01,  1.4028e01,  1.2318e01,  9.9124,
         7.4197,     5.5937,     4.4055,     4.1161,     4.4645,     4.5808,
         4.2918,     4.3506,     4.2065,     4.4100,     4.6715,     3.9185,
         2.6439,     2.1228,     2.0652,     2.3849,     3.3134,     3.6909,
         2.8225,     2.3885,     2.2150,     1.7230,     1.2312,     1.0585,
         1.2047,     1.3214,     1.1487,     1.0338,     1.1799,     1.5574,
         2.9208,     3.4142,     2.5164,     1.7921,     1.5609,     1.7352,
         2.2580,     1.9689,     1.5056,     1.3613,     1.5649,     2.0586,
         2.0595,     2.4080,     2.5825,     1.9750,     1.3964,     1.2813,
         1.3977,     1.8333,     1.8629,     1.8054,     2.0963,     2.1838,
         1.6639,     1.5200,     1.7824,     1.7258,     1.8138,     1.6993,
         1.7025,     1.6774,     1.6526,     1.5320,     1.4318,     1.3409,
         1.2958,     1.2874,     1.2789,     1.2609,     1.1881,     1.1245,
         1.1068,     1.0796,     1.0711,     1.0258,     9.9013e-01, 9.4546e-01,
         8.6468e-01, 8.0217e-01, 7.3974e-01, 6.9461e-01}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Interpolate(xCH4, yCH4, e);
    eta = 1.;
    return true;
  }

  double a, b, c, d;
  if (e < 285.) {
    a = -4.03133;
    b = 261.0982;
    c = -3005.43;
    d = 11572.96;
  } else if (e < 1740.) {
    a = -13.0225;
    b = 4303.263;
    c = -77622.4;
    d = 446724.9;
  } else {
    a = -1.11677;
    b = 3478.699;
    c = -48076.5;
    d = -364234.;
  }

  const double f = Evaluate(12.61 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsEthane(const double e, double& cs,
                                          double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109
  // Photoionization yield:
  // K. Kameta et al., J. El. Spectr. Rel. Phen. 123 (2002), 225-238

  if (e < 8.13) {
    cs = eta = 0.;
    return true;
  }

  if (e < 150.) {
    // Photoabsorption cross-section
    constexpr size_t nPacsEntries = 147;
    constexpr std::array<float, nPacsEntries> xC2H6 = {
        {8.1300,    8.2800,    8.5200,    8.6400,    8.7500,    8.8500,
         8.9100,    9.0000,    9.0500,    9.1300,    9.2000,    9.2700,
         9.3400,    9.4200,    9.4900,    9.5600,    9.6500,    9.7200,
         9.8000,    9.8800,    9.9400,    9.9900,    1.0310e01, 1.0580e01,
         1.0670e01, 1.0740e01, 1.0810e01, 1.0880e01, 1.0950e01, 1.1030e01,
         1.1100e01, 1.1180e01, 1.1240e01, 1.1330e01, 1.1410e01, 1.1520e01,
         1.1949e01, 1.2208e01, 1.2621e01, 1.2819e01, 1.3056e01, 1.3258e01,
         1.3655e01, 1.3900e01, 1.4179e01, 1.4511e01, 1.5083e01, 1.5792e01,
         1.6441e01, 1.7052e01, 1.8016e01, 1.8619e01, 1.9550e01, 2.0664e01,
         2.1500e01, 2.2000e01, 2.2500e01, 2.3000e01, 2.3500e01, 2.4000e01,
         2.4500e01, 2.5000e01, 2.5500e01, 2.6000e01, 2.6500e01, 2.7000e01,
         2.7500e01, 2.8000e01, 2.8500e01, 2.9000e01, 2.9500e01, 3.0000e01,
         3.1000e01, 3.2000e01, 3.3000e01, 3.4000e01, 3.5000e01, 3.6000e01,
         3.7000e01, 3.8000e01, 3.9000e01, 4.0000e01, 4.1000e01, 4.2000e01,
         4.3000e01, 4.4000e01, 4.5000e01, 4.6000e01, 4.7000e01, 4.8000e01,
         4.9000e01, 5.0000e01, 5.1000e01, 5.2000e01, 5.3000e01, 5.4000e01,
         5.5000e01, 5.6000e01, 5.7000e01, 5.8000e01, 5.9000e01, 6.0000e01,
         6.2000e01, 6.4000e01, 6.6000e01, 6.8000e01, 7.0000e01, 7.2000e01,
         7.4000e01, 7.6000e01, 7.8000e01, 8.0000e01, 8.2000e01, 8.4000e01,
         8.6000e01, 8.8000e01, 9.0000e01, 9.2000e01, 9.4000e01, 9.6000e01,
         9.8000e01, 1.0000e02, 1.0200e02, 1.0400e02, 1.0600e02, 1.0800e02,
         1.1000e02, 1.1200e02, 1.1400e02, 1.1600e02, 1.1800e02, 1.2000e02,
         1.2200e02, 1.2400e02, 1.2600e02, 1.2800e02, 1.3000e02, 1.3200e02,
         1.3400e02, 1.3600e02, 1.3800e02, 1.4000e02, 1.4200e02, 1.4400e02,
         1.4600e02, 1.4800e02, 1.5000e02}};
    constexpr std::array<float, nPacsEntries> yC2H6 = {
        {4.1354e-01, 1.3158,     2.8697,     3.5213,     5.0001,     9.9124,
         9.0853,     1.7030e01,  1.6379e01,  2.6128e01,  2.4161e01,  3.3334e01,
         2.9524e01,  3.5213e01,  3.0589e01,  3.4073e01,  2.8998e01,  3.1291e01,
         2.7519e01,  2.9324e01,  2.7607e01,  2.8334e01,  2.9299e01,  3.2582e01,
         3.5301e01,  3.4800e01,  3.7594e01,  3.5414e01,  3.8008e01,  3.5464e01,
         3.8584e01,  3.7507e01,  4.3008e01,  4.3747e01,  4.8434e01,  5.0890e01,
         5.3070e01,  5.6766e01,  5.5640e01,  5.7274e01,  6.7318e01,  7.3556e01,
         7.5569e01,  8.0471e01,  8.1976e01,  8.0471e01,  8.1597e01,  8.1099e01,
         7.9465e01,  7.5061e01,  7.1733e01,  7.0915e01,  6.5385e01,  5.9467e01,
         5.2518e01,  5.1042e01,  4.8168e01,  4.6086e01,  4.4358e01,  4.2783e01,
         4.0261e01,  3.8807e01,  3.6891e01,  3.6561e01,  3.3973e01,  3.1969e01,
         3.1451e01,  2.9403e01,  2.8742e01,  2.6969e01,  2.6066e01,  2.4370e01,
         2.2080e01,  2.1133e01,  1.9018e01,  1.7829e01,  1.6463e01,  1.5351e01,
         1.4415e01,  1.3677e01,  1.2576e01,  1.1926e01,  1.1012e01,  1.0219e01,
         9.6578,     9.1732,     8.6116,     8.4024,     7.8518,     7.4223,
         6.8717,     6.6184,     6.1779,     5.9356,     5.7154,     5.4511,
         4.9665,     4.8014,     4.5811,     4.4159,     4.0635,     3.8763,
         3.5570,     3.2927,     3.0504,     2.7861,     2.5879,     2.4227,
         2.2135,     2.0593,     1.9051,     1.7950,     1.6739,     1.5197,
         1.4646,     1.3875,     1.2995,     1.2114,     1.1673,     1.1233,
         1.0572,     1.0021,     9.8009e-01, 9.2503e-01, 8.9200e-01, 8.5896e-01,
         8.3693e-01, 7.8187e-01, 7.5985e-01, 7.3782e-01, 7.2681e-01, 6.9377e-01,
         6.6074e-01, 6.4973e-01, 6.1669e-01, 5.9466e-01, 5.7264e-01, 5.8365e-01,
         5.6163e-01, 5.1758e-01, 5.1758e-01, 4.9555e-01, 4.8454e-01, 4.6252e-01,
         4.6252e-01, 4.5150e-01, 4.4049e-01}};

    constexpr size_t nYieldEntries = 67;
    constexpr std::array<float, nYieldEntries> xIon = {
        {11.52,   11.6667, 11.8167, 12.,     12.1833, 12.2667, 12.4333, 12.65,
         12.8,    13.05,   13.25,   13.45,   13.5833, 13.6833, 13.7667, 13.95,
         14.2333, 14.4,    14.55,   14.7333, 14.8667, 15.,     15.15,   15.2833,
         15.45,   15.7333, 16.0167, 16.2833, 16.3333, 16.8167, 17.2,    17.4833,
         17.7333, 18.0167, 18.25,   18.3667, 18.5333, 18.7,    18.7833, 18.8667,
         18.9333, 19.,     19.1667, 19.2667, 19.3333, 19.4,    19.4667, 19.5667,
         19.6,    19.7,    19.7833, 19.9333, 20.,     20.0833, 20.2,    20.6,
         20.9333, 21.1333, 21.3167, 21.6167, 21.9833, 22.2333, 22.6,    22.9667,
         23.1667, 23.3833, 23.5667}};
    constexpr std::array<float, nYieldEntries> yIon = {
        {0.,      0.0034433, 0.055093, 0.12396, 0.21349, 0.25825, 0.33745,
         0.42697, 0.50789,   0.62324,  0.71966, 0.79197, 0.82984, 0.84706,
         0.8505,  0.84362,   0.83156,  0.82296, 0.81263, 0.80918, 0.81607,
         0.83329, 0.85395,   0.87461,  0.89871, 0.93314, 0.96069, 0.98135,
         0.98307, 0.99168,   0.99512,  0.98996, 0.98479, 0.98824, 0.99168,
         0.98824, 0.98824,   0.98135,  0.97618, 0.97963, 0.97618, 0.98135,
         0.98135, 0.97791,   0.97791,  0.98135, 0.97618, 0.97618, 0.97446,
         0.98135, 0.97446,   0.97102,  0.97274, 0.96758, 0.96758, 0.97446,
         0.97791, 0.97791,   0.97618,  0.97618, 0.97791, 0.97791, 0.97618,
         0.97791, 0.97446,   0.97446,  0.97446}};

    // Branching ratio (%) for dissociation to C2H5+ + H-
    constexpr size_t nBranchEntries = 50;
    constexpr std::array<float, nBranchEntries> xBranch = {
        {11., 11.5, 12., 12.5, 13., 13.5, 14., 14.5, 15., 15.5,
         16., 16.5, 17., 17.5, 18., 18.5, 19., 19.5, 20., 20.5,
         21., 21.5, 22., 22.5, 23., 23.5, 24., 24.5, 25., 25.5,
         26., 26.5, 27., 27.5, 28., 28.5, 29., 29.5, 30., 31.,
         32., 33.,  34., 35.,  36., 37.,  38., 39.,  40., 41.}};
    constexpr std::array<float, nBranchEntries> yBranch = {
        {0.,    0.,    2.8,   4.56,  8.98,  11.87, 13.21, 14.71, 14.6,  14.18,
         13.27, 13.28, 13.12, 12.78, 13.04, 13.16, 13.04, 13.11, 12.76, 12.62,
         12.27, 12.17, 12.28, 12.04, 11.94, 11.76, 11.73, 11.56, 11.24, 11.49,
         11.17, 11.,   11.04, 10.83, 10.8,  10.59, 10.65, 10.53, 10.27, 10.45,
         10.3,  10.24, 9.89,  9.28,  9.24,  9.4,   9.13,  9.41,  8.78,  9.54}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xC2H6, yC2H6, e);

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    const bool useBranching = true;
    if (useBranching) {
      double br = 0.;
      if (e < xBranch[0]) {
        br = 0.;
      } else if (e >= xBranch[nBranchEntries - 1]) {
        br = yBranch[nBranchEntries - 1];
      } else {
        // Linear interpolation.
        br = Interpolate(xBranch, yBranch, e);
      }
      eta *= (1. - 0.01 * br);
    }
    return true;
  }

  if (e >= 280. && e <= 320.) {
    // Carbon K edge

    constexpr size_t nEntries = 63;
    constexpr std::array<float, nEntries> xC2H6 = {
        {2.8000e02, 2.8618e02, 2.8638e02, 2.8670e02, 2.8698e02, 2.8723e02,
         2.8739e02, 2.8763e02, 2.8771e02, 2.8775e02, 2.8799e02, 2.8811e02,
         2.8819e02, 2.8827e02, 2.8847e02, 2.8860e02, 2.8872e02, 2.8892e02,
         2.8912e02, 2.8940e02, 2.8960e02, 2.8984e02, 2.9017e02, 2.9057e02,
         2.9089e02, 2.9129e02, 2.9158e02, 2.9182e02, 2.9206e02, 2.9238e02,
         2.9246e02, 2.9295e02, 2.9339e02, 2.9411e02, 2.9472e02, 2.9552e02,
         2.9657e02, 2.9770e02, 2.9883e02, 3.0012e02, 3.0060e02, 3.0132e02,
         3.0257e02, 3.0330e02, 3.0390e02, 3.0451e02, 3.0547e02, 3.0608e02,
         3.0692e02, 3.0757e02, 3.0829e02, 3.0914e02, 3.1015e02, 3.1127e02,
         3.1196e02, 3.1280e02, 3.1421e02, 3.1538e02, 3.1607e02, 3.1728e02,
         3.1820e02, 3.1909e02, 3.2000e02}};
    constexpr std::array<float, nEntries> yC2H6 = {
        {7.1950e-04, 1.0941e-03, 2.2763e-03, 9.7735e-03, 1.6678e-02, 1.7366e-02,
         1.8253e-02, 3.3250e-02, 4.8744e-02, 5.6341e-02, 5.9398e-02, 5.3673e-02,
         5.2686e-02, 4.9922e-02, 3.7782e-02, 3.2748e-02, 2.8108e-02, 2.7515e-02,
         2.8598e-02, 3.1950e-02, 3.7558,     3.9938,     4.2210,     4.3830,
         4.4259,     4.4363,     4.3602,     4.1867,     4.0239,     3.9370,
         3.8394,     3.6655,     3.4917,     3.3284,     3.2303,     3.0887,
         2.9251,     2.7830,     2.7276,     2.6288,     2.5741,     2.5408,
         2.4203,     2.3437,     2.3105,     2.3099,     2.1897,     2.1023,
         2.0581,     2.0358,     1.9809,     1.9691,     1.8814,     1.7935,
         1.7819,     1.7269,     1.6712,     1.6374,     1.5609,     1.5703,
         1.4935,     1.5034,     1.4807}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Interpolate(xC2H6, yC2H6, e);
    eta = 1.;
    return true;
  }

  double a, b, c, d;
  if (e < 280.) {
    a = -12.4308;
    b = 746.5164;
    c = -8913.93;
    d = 37174.85;
  } else if (e < 1740.) {
    a = 9.028358;
    b = 7916.428;
    c = -136533.;
    d = 745811.8;
  } else {
    a = -2.57845;
    b = 9040.533;
    c = -114924.;
    d = -2946480.;
  }

  const double f = Evaluate(11.52 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsAcetylene(const double e, double& cs,
                                             double& eta) {
  // Sources:

  // Photoabsorption cross-section:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109
  // Sub-ionization region:
  // G. Cooper at al., J. El. Spectr. Rel. Phen. (1995), 139-148
  // Photoionization yield:
  // M. Ukai et al., J. Chem. Phys. 95 (1991), 4142-4153

  if (e < 6.) {
    cs = eta = 0.;
    return true;
  }

  if (e < 62.) {
    // Photoabsorption cross-section
    constexpr size_t nPacsEntries = 196;
    constexpr std::array<float, nPacsEntries> xC2H2 = {
        {6.,        6.5,       7.,        7.5,       8.,        8.5,
         9.,        9.5,       10.,       10.5,      11.,       1.1401e01,
         1.1407e01, 1.1409e01, 1.1413e01, 1.1416e01, 1.1418e01, 1.1423e01,
         1.1424e01, 1.1428e01, 1.1431e01, 1.1433e01, 1.1437e01, 1.1440e01,
         1.1444e01, 1.1447e01, 1.1448e01, 1.1451e01, 1.1452e01, 1.1455e01,
         1.1457e01, 1.1460e01, 1.1462e01, 1.1474e01, 1.1478e01, 1.1481e01,
         1.1482e01, 1.1483e01, 1.1485e01, 1.1489e01, 1.1493e01, 1.1495e01,
         1.1496e01, 1.1500e01, 1.1503e01, 1.1507e01, 1.1509e01, 1.1511e01,
         1.1512e01, 1.1516e01, 1.1517e01, 1.1518e01, 1.1521e01, 1.1528e01,
         1.1529e01, 1.1530e01, 1.1533e01, 1.1534e01, 1.1538e01, 1.1543e01,
         1.1546e01, 1.1548e01, 1.1556e01, 1.1564e01, 1.1566e01, 1.1570e01,
         1.1573e01, 1.1576e01, 1.1578e01, 1.1580e01, 1.1582e01, 1.1583e01,
         1.1585e01, 1.1591e01, 1.1595e01, 1.1597e01, 1.1602e01, 1.1610e01,
         1.1616e01, 1.1617e01, 1.1619e01, 1.1621e01, 1.1623e01, 1.1625e01,
         1.1630e01, 1.1636e01, 1.1642e01, 1.1646e01, 1.1648e01, 1.1650e01,
         1.1660e01, 1.1669e01, 1.1670e01, 1.1672e01, 1.1676e01, 1.1680e01,
         1.1690e01, 1.1698e01, 1.1700e01, 1.1808e01, 1.2096e01, 1.2398e01,
         1.2716e01, 1.3051e01, 1.3260e01, 1.3335e01, 1.3458e01, 1.3643e01,
         1.3776e01, 1.3986e01, 1.4124e01, 1.4253e01, 1.4373e01, 1.4457e01,
         1.4641e01, 1.4723e01, 1.4831e01, 1.4967e01, 1.5041e01, 1.5127e01,
         1.5226e01, 1.5297e01, 1.5419e01, 1.5543e01, 1.5692e01, 1.5849e01,
         1.5967e01, 1.6068e01, 1.6177e01, 1.6314e01, 1.6531e01, 1.6761e01,
         1.6961e01, 1.7075e01, 1.7297e01, 1.7712e01, 1.7852e01, 1.7997e01,
         1.8134e01, 1.8268e01, 1.8530e01, 1.8791e01, 1.9074e01, 1.9762e01,
         2.0660e01, 2.1000e01, 2.1500e01, 2.2000e01, 2.2500e01, 2.3000e01,
         2.3500e01, 2.4000e01, 2.4500e01, 2.5000e01, 2.5500e01, 2.6000e01,
         2.6500e01, 2.7000e01, 2.7500e01, 2.8000e01, 2.8500e01, 2.9000e01,
         2.9500e01, 3.0000e01, 3.1000e01, 3.2000e01, 3.3000e01, 3.4000e01,
         3.5000e01, 3.6000e01, 3.7000e01, 3.8000e01, 3.9000e01, 4.0000e01,
         4.1000e01, 4.2000e01, 4.3000e01, 4.4000e01, 4.5000e01, 4.6000e01,
         4.7000e01, 4.8000e01, 4.9000e01, 5.0000e01, 5.1000e01, 5.2000e01,
         5.3000e01, 5.4000e01, 5.5000e01, 5.6000e01, 5.7000e01, 5.8000e01,
         5.9000e01, 6.0000e01, 6.1000e01, 6.2000e01}};
    constexpr std::array<float, nPacsEntries> yC2H2 = {
        {0.1537,    0.5049,    1.0976,    3.4794,    18.3081,   18.0776,
         33.4881,   48.9534,   39.3164,   37.8895,   33.7295,   2.6374e01,
         2.7607e01, 2.9974e01, 3.4365e01, 3.6190e01, 3.7176e01, 3.3769e01,
         3.0216e01, 2.5872e01, 2.3750e01, 2.3009e01, 2.2564e01, 2.3500e01,
         2.7298e01, 3.0899e01, 3.2330e01, 3.1392e01, 2.8678e01, 2.7295e01,
         2.6801e01, 2.6751e01, 2.7293e01, 2.4378e01, 2.5068e01, 2.6843e01,
         2.8669e01, 2.9507e01, 2.9802e01, 2.7926e01, 2.6987e01, 2.6296e01,
         2.6789e01, 2.5209e01, 2.3136e01, 2.2443e01, 2.2690e01, 2.4761e01,
         2.5353e01, 2.6042e01, 2.6487e01, 2.6782e01, 2.6041e01, 2.4855e01,
         2.5151e01, 2.6482e01, 2.7863e01, 2.9541e01, 3.0379e01, 2.8995e01,
         2.8599e01, 2.8648e01, 2.6474e01, 2.6472e01, 2.5731e01, 2.6026e01,
         2.6618e01, 2.6765e01, 2.7504e01, 2.7011e01, 2.8095e01, 2.7305e01,
         2.7107e01, 2.5428e01, 2.5328e01, 2.4784e01, 2.4783e01, 2.6211e01,
         2.7690e01, 2.7689e01, 2.8330e01, 2.7590e01, 2.7441e01, 2.7440e01,
         2.7636e01, 2.9066e01, 2.8866e01, 2.7730e01, 2.7729e01, 2.6544e01,
         2.5406e01, 2.7427e01, 2.8068e01, 2.8413e01, 2.7722e01, 2.7177e01,
         2.6928e01, 2.6333e01, 2.6185e01, 2.7955e01, 3.0723e01, 3.3612e01,
         3.6669e01, 4.1290e01, 4.5064e01, 4.6347e01, 4.6877e01, 4.5347e01,
         3.9997e01, 3.6467e01, 4.2647e01, 3.3408e01, 3.8117e01, 3.6117e01,
         3.7757e01, 4.1527e01, 4.4467e01, 5.5346e01, 5.4646e01, 5.8816e01,
         5.8816e01, 5.9936e01, 5.5756e01, 6.0936e01, 5.6056e01, 5.5526e01,
         5.6646e01, 5.2056e01, 5.3706e01, 5.1526e01, 4.9756e01, 4.6287e01,
         4.4177e01, 4.4177e01, 4.2937e01, 4.2407e01, 4.1467e01, 4.1937e01,
         4.1057e01, 4.1407e01, 4.0647e01, 3.9997e01, 3.9057e01, 3.6757e01,
         3.3782e01, 3.3080e01, 3.2443e01, 3.0874e01, 2.9809e01, 2.8514e01,
         2.7241e01, 2.5803e01, 2.4728e01, 2.4420e01, 2.2983e01, 2.2061e01,
         2.1413e01, 2.0711e01, 1.9975e01, 1.9163e01, 1.8592e01, 1.7956e01,
         1.7330e01, 1.6727e01, 1.5519e01, 1.4608e01, 1.3994e01, 1.3061e01,
         1.2413e01, 1.1875e01, 1.1272e01, 1.0624e01, 1.0229e01, 9.7572,
         9.2962,    8.8682,    8.3743,    8.0669,    7.7157,    7.3206,
         6.9036,    6.6621,    6.3767,    6.0145,    5.7182,    5.4987,
         5.2243,    4.9170,    4.7414,    4.3792,    4.2475,    3.9841,
         3.8414,    3.6658,    3.5341,    3.3146}};

    // Photoionization yield
    constexpr size_t nYieldEntries = 44;
    constexpr std::array<float, nYieldEntries> xIon = {
        {11.,   11.08, 11.55, 11.99, 12.53, 12.87, 13.21, 13.58, 13.65,
         13.92, 14.16, 14.29, 14.49, 14.56, 14.63, 15.03, 15.24, 15.41,
         15.47, 15.71, 15.74, 15.95, 16.08, 16.25, 16.49, 16.66, 16.76,
         17.03, 17.13, 17.47, 17.84, 18.38, 18.75, 18.95, 19.39, 19.76,
         20.00, 20.30, 20.54, 20.81, 21.69, 21.89, 22.33, 23.41}};

    constexpr std::array<float, nYieldEntries> yIon = {
        {0.16, 0.49, 0.70, 0.79, 0.7,  0.79, 0.78, 0.72, 0.69, 0.66, 0.63,
         0.66, 0.70, 0.73, 0.76, 0.82, 0.81, 0.81, 0.79, 0.80, 0.78, 0.77,
         0.77, 0.75, 0.76, 0.78, 0.81, 0.85, 0.89, 0.91, 0.94, 0.94, 0.95,
         0.97, 0.98, 0.98, 0.99, 0.98, 0.97, 0.98, 0.98, 0.97, 0.97, 0.97}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xC2H2, yC2H2, e);

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    return true;
  }

  if (e > 285. && e <= 360.) {
    // Carbon K edge

    constexpr size_t nEntries = 175;
    constexpr std::array<float, nEntries> xC2H2 = {
        {2.8481e02, 2.8506e02, 2.8535e02, 2.8553e02, 2.8561e02, 2.8579e02,
         2.8597e02, 2.8611e02, 2.8629e02, 2.8651e02, 2.8673e02, 2.8684e02,
         2.8702e02, 2.8730e02, 2.8733e02, 2.8735e02, 2.8736e02, 2.8739e02,
         2.8743e02, 2.8746e02, 2.8747e02, 2.8750e02, 2.8752e02, 2.8754e02,
         2.8755e02, 2.8756e02, 2.8759e02, 2.8763e02, 2.8766e02, 2.8774e02,
         2.8777e02, 2.8781e02, 2.8785e02, 2.8789e02, 2.8791e02, 2.8798e02,
         2.8801e02, 2.8808e02, 2.8814e02, 2.8818e02, 2.8821e02, 2.8827e02,
         2.8830e02, 2.8837e02, 2.8842e02, 2.8849e02, 2.8857e02, 2.8863e02,
         2.8867e02, 2.8871e02, 2.8874e02, 2.8876e02, 2.8879e02, 2.8881e02,
         2.8884e02, 2.8889e02, 2.8891e02, 2.8894e02, 2.8896e02, 2.8898e02,
         2.8900e02, 2.8904e02, 2.8906e02, 2.8909e02, 2.8914e02, 2.8917e02,
         2.8924e02, 2.8927e02, 2.8930e02, 2.8932e02, 2.8937e02, 2.8943e02,
         2.8948e02, 2.8952e02, 2.8955e02, 2.8959e02, 2.8961e02, 2.8964e02,
         2.8966e02, 2.8967e02, 2.8971e02, 2.8975e02, 2.8976e02, 2.8980e02,
         2.8982e02, 2.8985e02, 2.8988e02, 2.8991e02, 2.8993e02, 2.8996e02,
         2.9000e02, 2.9004e02, 2.9009e02, 2.9014e02, 2.9017e02, 2.9019e02,
         2.9023e02, 2.9025e02, 2.9028e02, 2.9030e02, 2.9033e02, 2.9037e02,
         2.9039e02, 2.9040e02, 2.9044e02, 2.9046e02, 2.9050e02, 2.9057e02,
         2.9060e02, 2.9063e02, 2.9066e02, 2.9068e02, 2.9070e02, 2.9073e02,
         2.9075e02, 2.9080e02, 2.9083e02, 2.9085e02, 2.9086e02, 2.9090e02,
         2.9094e02, 2.9097e02, 2.9099e02, 2.9102e02, 2.9104e02, 2.9107e02,
         2.9111e02, 2.9118e02, 2.9121e02, 2.9125e02, 2.9132e02, 2.9136e02,
         2.9138e02, 2.9140e02, 2.9142e02, 2.9146e02, 2.9150e02, 2.9190e02,
         2.9298e02, 2.9385e02, 2.9476e02, 2.9552e02, 2.9588e02, 2.9649e02,
         2.9703e02, 2.9761e02, 2.9852e02, 2.9949e02, 2.9996e02, 3.0034e02,
         3.0077e02, 3.0124e02, 3.0184e02, 3.0334e02, 3.0467e02, 3.0622e02,
         3.0777e02, 3.0910e02, 3.1030e02, 3.1197e02, 3.1425e02, 3.1675e02,
         3.2018e02, 3.2341e02, 3.2702e02, 3.3003e02, 3.3342e02, 3.3656e02,
         3.4000e02, 3.4335e02, 3.4683e02, 3.5013e02, 3.5344e02, 3.5731e02,
         3.6000e02}};
    constexpr std::array<float, nEntries> yC2H2 = {
        {1.1447,    4.0960,    8.2636,    1.2449e01, 1.4649e01, 1.5865e01,
         1.4505e01, 1.1662e01, 7.4408,    4.1139,    1.6456,    1.0374,
         6.0814e-1, 2.9716e-1, 3.5206e-1, 3.4023e-1, 4.3127e-1, 3.7713e-1,
         4.5638e-1, 3.5374e-1, 4.3878e-1, 4.5737e-1, 3.7275e-1, 4.3971e-1,
         5.3069e-1, 4.6422e-1, 4.9481e-1, 7.9837e-1, 8.4119e-1, 1.7211,
         1.8306,    1.6857,    1.6801,    1.7714,    1.8021,    2.0091,
         2.0094,    1.5558,    1.2111,    1.1693,    1.1757,    1.3038,
         1.3284,    1.1657,    1.0754,    1.0519,    1.1258,    1.3205,
         1.7575,    2.7459,    3.9887,    4.6132,    4.7893,    4.6867,
         4.4506,    3.6390,    3.0393,    2.5792,    2.4340,    2.4403,
         2.5799,    2.9743,    3.0898,    2.9750,    2.5756,    2.0670,
         1.6921,    1.5470,    1.4747,    1.4567,    1.3301,    1.1066,
         1.0527,    1.1078,    1.2416,    1.6360,    2.3454,    3.2185,
         3.4369,    3.3281,    2.5163,    1.7835,    1.6686,    1.4691,
         1.4754,    1.5910,    1.8277,    2.3978,    2.7313,    2.9197,
         2.8232,    2.4965,    1.8122,    1.5219,    1.5223,    1.6075,
         1.9595,    2.0446,    2.5480,    2.6635,    2.4760,    1.8946,
         1.8039,    1.7678,    1.7742,    1.9079,    2.0054,    2.3941,
         2.2855,    1.9888,    1.8015,    1.7895,    1.8625,    2.0083,
         2.1481,    2.1003,    2.1248,    2.1069,    2.1253,    2.0590,
         1.9626,    2.0055,    2.0118,    2.0970,    2.0973,    2.0492,
         2.0800,    2.0567,    2.0389,    2.0819,    2.1010,    2.0711,
         2.0897,    2.0778,    2.0962,    2.0544,    2.0729,    2.1464,
         2.2537,    2.1285,    2.2001,    2.4862,    2.5756,    2.3968,
         2.1643,    2.0391,    2.0211,    2.0391,    2.0927,    2.0805,
         2.1235,    2.0752,    2.0672,    2.1183,    2.1855,    2.2206,
         2.2475,    2.2718,    2.2692,    2.2640,    2.1756,    2.0712,
         1.9159,    1.7846,    1.6669,    1.5921,    1.5226,    1.4665,
         1.4132,    1.3679,    1.3306,    1.2879,    1.2507,    1.2188,
         1.2169}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xC2H2, yC2H2, e);
    eta = 1.;
    return true;
  }

  double a, b, c, d;
  if (e < 285.) {
    a = -4.09582;
    b = 371.7201;
    c = -3488.22;
    d = 11226.67;
  } else if (e < 1740.) {
    a = 14.12306;
    b = 7389.95;
    c = -105703.;
    d = 259751.7;
  } else {
    a = -2.73231;
    b = 9413.515;
    c = -143892.;
    d = -1205737.;
  }

  const double f = Evaluate(11.4011 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsCF4(const double e, double& cs,
                                       double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. W. Au et al., Chem. Phys. 221 (1997), 151-168
  // Photoionisation yield:
  // Zhang et al., Chemical Physics 137 (1989), 391-405

  if (e < 10.) {
    cs = eta = 0.;
    return true;
  }

  if (e < 200.) {
    // Differential oscillator strength
    constexpr size_t nPacsEntries = 255;
    constexpr std::array<float, nPacsEntries> xCF4 = {
        {10.0, 10.5, 11.0, 11.5,
         // High resolution data (from plot)
         11.66, 11.88, 12.06, 12.14, 12.26, 12.42, 12.58, 12.81, 12.95, 13.11,
         13.17, 13.21, 13.25, 13.27, 13.29, 13.31, 13.35, 13.37, 13.39, 13.43,
         13.45, 13.47, 13.49, 13.51, 13.53, 13.61, 13.67, 13.73, 13.85, 13.97,
         14.03, 14.09, 14.13, 14.15, 14.17, 14.21, 14.23, 14.28, 14.32, 14.34,
         14.36, 14.40, 14.42, 14.54, 14.62, 14.72, 14.82, 14.88, 14.98, 15.08,
         15.20, 15.26, 15.36, 15.40, 15.48, 15.50, 15.52, 15.56, 15.60, 15.64,
         15.68, 15.72, 15.75, 15.79, 15.83, 15.89, 15.95, 15.99, 16.03, 16.05,
         16.11, 16.15, 16.19, 16.37, 16.47, 16.63, 16.75, 16.93, 17.11, 17.25,
         17.48, 17.72, 18.00, 18.18, 18.38, 18.58, 18.81, 18.93, 19.03, 19.13,
         19.17, 19.27, 19.43, 19.61, 19.78, 19.93,
         // 12.0,  12.5,  13.0,  13.5,  14.0,  14.5,
         // 15.0,  15.5,  16.0,  16.5,  17.0,  17.5,  18.0,  18.5,  19.0,  19.5,
         20.0, 20.5, 21.0, 21.5, 22.0, 22.5, 23.0, 23.5, 24.0, 24.5, 25.0, 25.5,
         26.0, 26.5, 27.0, 27.5, 28.0, 28.5, 29.0, 29.5, 30.0, 30.5, 31.0, 31.5,
         32.0, 32.5, 33.0, 33.5, 34.0, 34.5, 35.0, 35.5, 36.0, 36.5, 37.0, 37.5,
         38.0, 38.5, 39.0, 39.5, 40.0, 40.5, 41.0, 41.5, 42.0, 42.5, 43.0, 43.5,
         44.0, 44.5, 45.0, 45.5, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0,
         54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, 64.0, 65.0,
         66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0,
         78.0, 79.0, 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0,
         90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 98.0, 100.0, 102.0, 104.0,
         106.0, 108.0, 110.0, 112.0, 114.0, 116.0, 118.0, 120.0, 122.0, 124.0,
         126.0, 128.0, 130.0, 132.0, 134.0, 136.0, 138.0, 140.0, 142.0, 144.0,
         146.0, 148.0, 150.0, 152.0, 154.0, 156.0, 158.0, 160.0, 162.0, 164.0,
         166.0, 168.0, 170.0, 172.0, 174.0, 176.0, 178.0, 180.0, 182.0, 184.0,
         186.0, 188.0, 190.0, 192.0, 194.0, 196.0, 198.0, 200.0}};

    constexpr std::array<float, nPacsEntries> yCF4 = {
        {0.05, 0.06, 0.10, 0.27,
         // High resolution data (from plot)
         0.29, 0.29, 0.44, 1.47, 1.91, 3.08, 3.67, 3.67, 3.23, 3.37, 4.11, 6.09,
         8.80, 10.56, 12.32, 14.23, 18.92, 23.03, 28.53, 34.62, 38.88, 40.78,
         42.54, 43.86, 46.65, 47.68, 46.50, 44.74, 41.96, 42.10, 40.49, 37.48,
         34.99, 33.30, 31.69, 30.04, 28.31, 25.53, 24.21, 22.30, 20.83, 19.36,
         18.34, 15.26, 13.20, 11.30, 9.68, 8.36, 7.63, 8.95, 11.00, 12.76,
         15.55, 17.75, 20.39, 23.62, 25.53, 28.61, 31.69, 35.50, 41.00, 44.30,
         47.53, 49.29, 51.05, 48.85, 44.89, 42.25, 39.32, 37.56, 34.47, 31.83,
         29.63, 32.57, 34.03, 36.38, 38.44, 39.76, 39.46, 39.61, 41.81, 43.57,
         45.77, 46.94, 47.82, 47.24, 46.36, 46.21, 47.53, 49.00, 50.46, 52.37,
         54.43, 51.64, 49.58, 48.41,
         // 1.32,  3.51, 11.97, 29.62, 31.67, 19.92,
         // 16.82, 28.76, 35.24, 35.92, 39.14, 41.84, 44.86, 46.84, 48.48,
         // 49.98,
         51.66, 55.96, 58.65, 60.84, 62.47, 62.01, 60.63, 59.36, 57.26, 54.58,
         52.55, 50.40, 48.52, 47.15, 45.89, 45.11, 44.67, 44.49, 44.27, 44.27,
         44.35, 44.61, 44.67, 44.30, 44.56, 44.15, 44.20, 44.42, 44.23, 43.65,
         43.44, 43.23, 42.79, 42.69, 42.52, 42.77, 42.65, 42.56, 42.98, 42.57,
         42.33, 41.93, 41.10, 40.51, 39.84, 38.82, 37.73, 36.62, 35.71, 35.18,
         34.05, 33.21, 32.14, 30.72, 29.45, 28.25, 27.56, 26.71, 26.11, 25.50,
         24.91, 24.40, 23.91, 23.60, 23.14, 22.60, 22.35, 21.92, 21.40, 21.06,
         20.52, 20.17, 19.92, 19.55, 19.00, 18.84, 18.39, 18.05, 17.81, 17.31,
         17.06, 16.62, 16.43, 16.02, 15.74, 15.43, 15.12, 14.64, 14.57, 14.05,
         13.87, 13.62, 13.51, 13.24, 12.74, 12.66, 12.47, 12.18, 11.84, 11.73,
         11.50, 11.23, 11.01, 10.61, 10.33, 9.98, 9.65, 9.31, 9.02, 8.65, 8.43,
         8.13, 7.86, 7.64, 7.35, 7.15, 6.94, 6.71, 6.45, 6.27, 6.09, 5.91, 5.69,
         5.56, 5.30, 5.18, 5.03, 4.87, 4.74, 4.52, 4.42, 4.27, 4.15, 4.13, 3.94,
         3.89, 3.80, 3.75, 3.58, 3.46, 3.35, 3.26, 3.17, 3.10, 3.13, 2.99, 2.91,
         2.79, 2.67, 2.68, 2.72, 2.55, 2.52, 2.45, 2.42}};

    // Photoionization yield
    constexpr size_t nYieldEntries = 10;
    constexpr std::array<float, nYieldEntries> xIon = {
        {15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5, 20.0}};
    constexpr std::array<float, nYieldEntries> yIon = {
        {0.03, 0.14, 0.28, 0.50, 0.68, 0.84, 0.93, 0.95, 0.97, 1.0}};

    // First the photoabsorption cross-section.
    // Linear interpolation.
    cs = Interpolate(xCF4, yCF4, e);
    // Data in the table are given in 0.01 eV-1.
    cs *= 0.01;
    // Convert from oscillator strength to photoabsorption cs.
    cs *= 109.75e-18;

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Linear interpolation.
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    return true;
  }

  cs = eta = 0.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsButane(const double e, double& cs,
                                          double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. W. Au et al., Chem. Phys. 173 (1993), 209-239
  // Photoionisation yield:
  // J. W. Au, G. Cooper and C. E. Brion, Chem. Phys. 173 (1993), 241-265

  if (e < 7.62) {
    cs = eta = 0.;
    return true;
  }

  if (e < 25.04) {
    // Differential oscillator strength
    constexpr size_t nPacsEntries = 40;
    constexpr std::array<float, nPacsEntries> xC4H10 = {
        {7.61194, 8.0597,  8.29851, 8.38806, 8.50746, 8.65672, 9.01493,
         9.19403, 9.49254, 9.85075, 10.0299, 10.2985, 10.5672, 10.6567,
         11.0324, 11.5044, 12.0059, 12.5369, 12.8319, 13.1268, 13.2153,
         13.5693, 13.9233, 14.2478, 14.7198, 15.2802, 16.1062, 16.7552,
         17.2861, 17.7581, 18.2301, 18.8791, 19.6755, 20.354,  21.1504,
         21.9469, 22.6254, 23.5693, 24.2773, 25.0442}};
    constexpr std::array<float, nPacsEntries> yC4H10 = {
        {0.,      1.80412, 9.02062, 15.8763, 24.5361, 31.3918, 32.1134,
         37.5258, 42.2165, 39.6907, 41.134,  47.9897, 53.4021, 55.2062,
         61.8598, 70.7547, 80.4582, 90.566,  101.482, 110.377, 118.868,
         123.315, 131.402, 139.892, 144.34,  148.787, 150.809, 146.766,
         143.531, 137.062, 131.402, 126.55,  119.272, 112.803, 103.1,
         95.0135, 88.5445, 81.2668, 74.3935, 68.3288}};

    // Photoionization yield
    constexpr size_t nYieldEntries = 9;
    constexpr std::array<float, nYieldEntries> xIon = {
        {10., 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0}};
    constexpr std::array<float, nYieldEntries> yIon = {
        {0.04, 0.148, 0.319, 0.501, 0.717, 0.832, 0.880, 0.943, 1.}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Mbarn * Interpolate(xC4H10, yC4H10, e);

    if (e < xIon[0]) {
      eta = 0.;
    } else if (e >= xIon[nYieldEntries - 1]) {
      eta = 1.;
    } else {
      // Same procedure as for photoabsorption cross-section.
      eta = Interpolate(xIon, yIon, e);
    }

    return true;
  }

  cs = eta = 0.;
  return true;
}

bool OpticalData::PhotoAbsorptionCsNitrogen(const double e, double& cs,
                                            double& eta) {
  // Sources:
  // Photoabsorption cross-section:
  // J. Berkowitz, Atomic and Molecular Photoabsorption (2002)
  // N. Sakamoto et al., NIFS-DATA 109
  // Photoionization yield:

  if (e < 14.92) {
    cs = eta = 0.;
    return true;
  }

  if (e < 150.) {
    // Photoabsorption cross-section
    constexpr size_t nPacsEntries = 198;
    constexpr std::array<float, nPacsEntries> xN2 = {
        {1.4920e01, 1.4949e01, 1.4974e01, 1.4996e01, 1.5005e01, 1.5014e01,
         1.5057e01, 1.5104e01, 1.5115e01, 1.5188e01, 1.5197e01, 1.5230e01,
         1.5242e01, 1.5271e01, 1.5295e01, 1.5321e01, 1.5368e01, 1.5373e01,
         1.5404e01, 1.5419e01, 1.5458e01, 1.5477e01, 1.5511e01, 1.5514e01,
         1.5540e01, 1.5580e01, 1.5601e01, 1.5611e01, 1.5640e01, 1.5661e01,
         1.5686e01, 1.5709e01, 1.5732e01, 1.5766e01, 1.5787e01, 1.5806e01,
         1.5821e01, 1.5827e01, 1.5851e01, 1.5862e01, 1.5872e01, 1.5879e01,
         1.5891e01, 1.5915e01, 1.5924e01, 1.5942e01, 1.5964e01, 1.5973e01,
         1.5989e01, 1.6006e01, 1.6024e01, 1.6034e01, 1.6055e01, 1.6072e01,
         1.6091e01, 1.6101e01, 1.6113e01, 1.6127e01, 1.6161e01, 1.6180e01,
         1.6212e01, 1.6232e01, 1.6255e01, 1.6291e01, 1.6327e01, 1.6352e01,
         1.6385e01, 1.6400e01, 1.6425e01, 1.6435e01, 1.6476e01, 1.6493e01,
         1.6507e01, 1.6536e01, 1.6558e01, 1.6587e01, 1.6613e01, 1.6654e01,
         1.6673e01, 1.6703e01, 1.6731e01, 1.6764e01, 1.6808e01, 1.6844e01,
         1.6889e01, 1.6906e01, 1.6942e01, 1.7000e01, 1.7031e01, 1.7063e01,
         1.7075e01, 1.7104e01, 1.7142e01, 1.7169e01, 1.7198e01, 1.7239e01,
         1.7269e01, 1.7308e01, 1.7335e01, 1.7364e01, 1.7386e01, 1.7425e01,
         1.7461e01, 1.7533e01, 1.7579e01, 1.7596e01, 1.7625e01, 1.7704e01,
         1.7731e01, 1.7745e01, 1.7772e01, 1.7803e01, 1.7837e01, 1.7849e01,
         1.7866e01, 1.7897e01, 1.7922e01, 1.7958e01, 1.8000e01, 1.8118e01,
         1.8151e01, 1.8176e01, 1.8233e01, 1.8280e01, 1.8312e01, 1.8352e01,
         1.8408e01, 1.8424e01, 1.8462e01, 1.8480e01, 1.8504e01, 1.8616e01,
         1.8786e01, 2.0000e01, 2.2500e01, 2.5000e01, 2.7500e01, 3.0000e01,
         3.5000e01, 4.0000e01, 4.5000e01, 5.0000e01, 6.0000e01, 7.0000e01,
         8.0000e01, 9.0000e01, 1.0000e02, 1.2500e02, 1.5000e02, 1.7500e02,
         2.0000e02, 2.2500e02, 2.5000e02, 2.7500e02, 3.0000e02, 3.5000e02,
         4.0000e02, 4.0740e02, 4.0777e02, 4.0794e02, 4.0799e02, 4.0819e02,
         4.0859e02, 4.0915e02, 4.0964e02, 4.1000e02, 4.1009e02, 4.1169e02,
         4.1194e02, 4.1230e02, 4.1259e02, 4.1319e02, 4.1375e02, 4.1418e02,
         4.1442e02, 4.1485e02, 4.1532e02, 4.1583e02, 4.1625e02, 4.1677e02,
         4.1715e02, 4.1766e02, 4.1809e02, 4.1862e02, 4.1902e02, 4.1947e02,
         4.2000e02, 4.2060e02, 4.2132e02, 4.2217e02, 4.2306e02, 4.2411e02,
         4.2520e02, 4.2619e02, 4.2722e02, 4.2809e02, 4.2896e02, 4.3000e02}};
    constexpr std::array<float, nPacsEntries> yN2 = {
        {2.6696,     3.5876,     7.0085,     1.4017e01,  1.8550e01,  2.2525e01,
         8.8070,     2.3226e01,  3.4138e01,  9.8988,     1.2080e01,  3.3358e01,
         3.6631e01,  1.5900e01,  8.5734,     1.3016e01,  3.8269e01,  4.0996e01,
         1.9563e01,  1.5665e01,  3.0240e01,  3.3825e01,  1.5821e01,  1.3172e01,
         1.0833e01,  1.8924e01,  3.0576e01,  3.1046e01,  4.3518e01,  5.1143e01,
         4.0351e01,  2.8074e01,  1.7673e01,  2.5493e01,  3.7458e01,  6.1543e01,
         6.9207e01,  6.5218e01,  4.4418e01,  4.0116e01,  3.8866e01,  3.5425e01,
         2.9090e01,  2.3929e01,  2.3069e01,  2.4945e01,  3.9257e01,  4.7936e01,
         5.0674e01,  3.5425e01,  2.9404e01,  3.3117e01,  4.5669e01,  4.7545e01,
         3.3626e01,  2.8230e01,  2.5727e01,  2.6744e01,  2.4711e01,  3.0771e01,
         4.0899e01,  3.2883e01,  2.8074e01,  3.2296e01,  2.5572e01,  2.9168e01,
         2.8660e01,  2.6901e01,  3.3313e01,  3.6285e01,  2.2600e01,  2.2130e01,
         2.2757e01,  2.9404e01,  2.7174e01,  2.7096e01,  2.6002e01,  2.9638e01,
         2.7135e01,  2.0957e01,  2.2366e01,  2.6041e01,  2.5806e01,  2.3694e01,
         2.3929e01,  2.1114e01,  2.2052e01,  2.5181e01,  2.7369e01,  3.2180e01,
         3.2687e01,  4.1367e01,  4.8093e01,  3.7770e01,  3.0420e01,  2.8699e01,
         2.5572e01,  2.1036e01,  2.0410e01,  2.5181e01,  2.6901e01,  2.7605e01,
         2.6041e01,  2.5806e01,  2.6118e01,  2.5884e01,  2.4515e01,  2.4554e01,
         2.3694e01,  2.4633e01,  2.4633e01,  2.7369e01,  3.6832e01,  3.9022e01,
         3.8474e01,  2.8465e01,  2.7135e01,  2.2678e01,  2.5181e01,  2.6588e01,
         3.1671e01,  3.3782e01,  2.4750e01,  2.5024e01,  2.6353e01,  3.1123e01,
         2.5024e01,  2.5884e01,  2.8934e01,  2.7135e01,  2.6744e01,  2.6509e01,
         2.7135e01,  2.3597e01,  2.4160e01,  2.3413e01,  2.1919e01,  2.0116e01,
         1.6487e01,  1.3377e01,  1.0896e01,  8.9532,     6.2399,     4.5290,
         3.4047,     2.6360,     2.0917,     1.2460,     8.2418e-01, 5.6986e-01,
         4.0682e-01, 3.0251e-01, 2.3146e-01, 1.8009e-01, 1.4169e-01, 8.9704E-02,
         5.7876E-02, 2.2214e-01, 3.4866e-01, 6.1463e-01, 8.4375e-01, 8.9953e-01,
         9.1348e-01, 8.4973e-01, 9.6329e-01, 1.0151,     1.0021,     1.0460,
         1.1486,     1.2452,     1.3279,     1.5411,     1.7463,     1.8867,
         1.9286,     1.9594,     1.9236,     1.8509,     1.8150,     1.9067,
         1.9923,     2.1228,     2.2224,     2.2414,     2.2105,     2.1139,
         2.0202,     1.9316,     1.8489,     1.7821,     1.7214,     1.6606,
         1.5968,     1.5550,     1.5052,     1.4753,     1.4444,     1.4116}};

    // Interpolate and convert from Mbarn to cm2.
    cs = Interpolate(xN2, yN2, e);
    eta = 0.;

    return true;
  }

  double a, b, c, d;
  if (e < 285.) {
    a = -4.03133;
    b = 261.0982;
    c = -3005.43;
    d = 11572.96;
  } else if (e < 1740.) {
    a = -13.0225;
    b = 4303.263;
    c = -77622.4;
    d = 446724.9;
  } else {
    a = -1.11677;
    b = 3478.699;
    c = -48076.5;
    d = -364234.;
  }

  const double f = Evaluate(12.61 / e, a, b, c, d);
  // Convert from oscillator strength (per Rydberg) to photoabsorption cs
  cs = OscToPacs * f;
  eta = 1.;
  return true;
}
}
